{"id":403,"date":"2025-04-24T19:29:44","date_gmt":"2025-04-24T19:29:44","guid":{"rendered":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/?p=403"},"modified":"2025-04-24T19:29:44","modified_gmt":"2025-04-24T19:29:44","slug":"tuple-functions-and-module-in-python","status":"publish","type":"post","link":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/2025\/04\/24\/tuple-functions-and-module-in-python\/","title":{"rendered":"Tuple, Functions and Module in Python"},"content":{"rendered":"\n<p>Question (1) <br>a. What is the significance of using function in python programming?<br><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Functions are reusable and can perform specific tasks<\/mark><br>b. What does the following statement do? You may execute this in Python IDE<br>and submit the screenshot for the output.<br>print(random.uniform(0.1, 0.5))<br><mark class=\"has-inline-color has-vivid-cyan-blue-color\">This function prints any random floating variable between the two given numbers (0.1<br>&amp; 0.5)<\/mark><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"630\" src=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-150359.png\" alt=\"\" class=\"wp-image-400\" style=\"width:277px;height:auto\" srcset=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-150359.png 598w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-150359-285x300.png 285w\" sizes=\"(max-width: 598px) 100vw, 598px\" \/><\/figure>\n\n\n\n<p>c. List five built-in functions in python.<br><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Five built-in functions in python are max(), help(), sum(), input(), and print().<\/mark><br>d. What is meant by scope of a variable in python (function)? Explain with an<br>example.<br><mark class=\"has-inline-color has-vivid-cyan-blue-color\">The scope refers to where the variable is available or able to be used.<\/mark><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"815\" height=\"416\" src=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-150958.png\" alt=\"\" class=\"wp-image-404\" srcset=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-150958.png 815w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-150958-300x153.png 300w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-150958-768x392.png 768w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-150958-588x300.png 588w\" sizes=\"(max-width: 815px) 100vw, 815px\" \/><\/figure>\n\n\n\n<p>Question (2) <br>a. What is difference between list, Tuple and Dictionary in python?<br><mark class=\"has-inline-color has-vivid-cyan-blue-color\">All of these are collections of values. Lists and tuples are both ordered but unlike lists,<br>tuples cannot be changed. Dictionaries are unordered.<\/mark><br>b. What is tuple in python? Explain with an example.<br><mark class=\"has-inline-color has-vivid-cyan-blue-color\">A tuple is much like a list however it uses () instead of [] and cannot be edited as shown in the<br>example.<br>Inside scope<br>of function<br>Outside scope<br>of function<\/mark><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/canvadocs.instructure.com\/images\/icons\/create-comment-icon.svg\" alt=\"Create comment icon\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"816\" height=\"559\" src=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151136.png\" alt=\"\" class=\"wp-image-405\" style=\"width:422px;height:auto\" srcset=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151136.png 816w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151136-300x206.png 300w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151136-768x526.png 768w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151136-438x300.png 438w\" sizes=\"(max-width: 816px) 100vw, 816px\" \/><\/figure>\n\n\n\n<p>c. What is a module in python? How would you access a module in python?<br>Explain with an example.<br><mark class=\"has-inline-color has-vivid-cyan-blue-color\">A module is defined as a file with a python code like functions in it. All of the circles areas<br>from pycharm are different modules or files including python codes and functions.<\/mark><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"959\" height=\"64\" src=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151518.png\" alt=\"\" class=\"wp-image-406\" srcset=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151518.png 959w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151518-300x20.png 300w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151518-768x51.png 768w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151518-600x40.png 600w\" sizes=\"(max-width: 959px) 100vw, 959px\" \/><\/figure>\n\n\n\n<p>Question (3) <br>a. Using\/importing \u201cmath\u201d library\/module, use the built-in function (You<br>need to explore the function online) to find the largest item from a given list. Please<br>submit the screenshot for your code and its output. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"918\" height=\"338\" src=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151834.png\" alt=\"\" class=\"wp-image-407\" srcset=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151834.png 918w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151834-300x110.png 300w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151834-768x283.png 768w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151834-600x221.png 600w\" sizes=\"(max-width: 918px) 100vw, 918px\" \/><\/figure>\n\n\n\n<p>b. Write a function in python, that should do the following:<br>i) add(num1, num2): Returns the sum of two numbers num1 and num2.<br>ii) subtract(num1, num2): Returns the result of subtracting num2 from num1.<br>iii) multiply(num1, num2): Returns the product of two numbers num1 and num2.<br>Please submit the screenshot for your code and its output.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"876\" height=\"913\" src=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151959.png\" alt=\"\" class=\"wp-image-408\" srcset=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151959.png 876w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151959-288x300.png 288w, https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-content\/uploads\/sites\/34338\/2025\/04\/Screenshot-2025-04-24-151959-768x800.png 768w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Question (1) a. What is the significance of using function in python programming?Functions are reusable and can perform specific tasksb. What does the following statement do? You may execute this in Python IDEand submit the screenshot for the output.print(random.uniform(0.1, 0.5))This function prints any random floating variable between the two given numbers (0.1&amp; 0.5) c. List&#8230; <\/p>\n<div class=\"link-more\"><a href=\"https:\/\/sites.wp.odu.edu\/aurorafrancis\/2025\/04\/24\/tuple-functions-and-module-in-python\/\">Read More<\/a><\/div>\n","protected":false},"author":27605,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","wds_primary_category":26},"categories":[26],"tags":[28,27],"_links":{"self":[{"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/posts\/403"}],"collection":[{"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/users\/27605"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/comments?post=403"}],"version-history":[{"count":1,"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/posts\/403\/revisions"}],"predecessor-version":[{"id":409,"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/posts\/403\/revisions\/409"}],"wp:attachment":[{"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/media?parent=403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/categories?post=403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.wp.odu.edu\/aurorafrancis\/wp-json\/wp\/v2\/tags?post=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}