Computer Science  >  CODING SOLUTION  >  CS 1101 Programming Fundamentals - Term 5, 2018-2019CS 1101 - AY2019-T5_ Discussion Unit 2. With an (All)

CS 1101 Programming Fundamentals - Term 5, 2018-2019CS 1101 - AY2019-T5_ Discussion Unit 2. With answers

Document Content and Description Below

CS 1101 Programming Fundamentals - Term 5, 2018-2019CS 1101 - AY2019-T5_ Discussion Unit 2. With answers Create your own Python code examples that demonstrate each of the following. Do not copy ex ... amples from the book or any other source. Try to be creative with your examples to demonstrate that you invented them yourself. Example 1: Dene a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter. Example 2: Call your function from Example 1 three times with dierent kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which. Example 3: Create a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results. Example 4: Create a function that takes an argument. Give the function parameter a unique name. Show what happens when you try to use that parameter name outside the function. 21/8/2019 CS 1101 - AY2019-T5: Discussion Unit 2 https://my.uopeople.edu/mod/forum/discuss.php?d=230935 2/54 Explain the results. Example 5: Show what happens when a variable dened outside a function has the same name as a local variable inside a function. Explain what happens to the value of each variable as the program runs. For this Discussion forum, here are my examples and what I have done to complete it, I hope I'm not mistaking anything. #Example 1: Dene a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter. #Here I dene the function that will display a message per name def congratulation(name): # congratulation is the function the (name) is the argument print("congratulation to you!" + name) # I will call my function, in this case, it will print the name below which is Paul & Roza are considered as a parameter congratulation ("Paul") congratulation ("Roza") #Example 2: Call your function from Example 1 three times with dierent kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which. # call my function with a value congratulation ("Liza") # call my function with a variable variableName="Reem" congratulation (variableName) # call my functiion with an expression congratulation ("Mr SRAYI Reda ") #Example 3: Create a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results. 21/8/2019 CS 1101 - AY2019-T5: Discussion Unit 2 https://my.uopeople.edu/mod/forum/discuss.php?d=230935 3/54 def printCountry(): country = "France" capital = "Paris" print (capital + " is the capital of " + country) printCountry() #Let's show variables country and capital outside the function printCountry ==> this will create an error because capital and country are dened outside the function print (capital + " is the capital of " + country) (on the attached le remove the # for commenting in order to test ) #Traceback (most recent call last): #File "C:\Users\rsrayi\AppData\Local\Programs\Python\Python37-32\Scripts\Discussion Forum U nit 2.py", line 36, in <module> #print (capital + " is the capital of " + country) #NameError: name 'capital' is not defined #Example 4: Create a function that takes an argument. Give the function parameter a unique name. Show what happens when you try to use that parameter name outside the function. Explain the results. def returnCarModel(model): print ("the model is " + model) print ("this is a good model !!!") returnCarModel ("Honda") #Lets call varianle model outside the function == > this will create an error print(model) # ===> NameError: name 'model' is not defined (make sure you remove the # from m y attached script if you want test) #Traceback (most recent call last): #File "C:\Users\rsrayi\AppData\Local\Programs\Python\Python37-32\Scripts\Discussion Forum U nit 2.py", line 50, in <module> #print(model) # ===> NameError: name 'model' is not defined #NameError: name 'model' is not defined #Example 5: Show what happens when a variable dened outside a function has the same name as a local variable inside a function. Explain what happens to the value of each variable as the program runs. 21/8/2019 CS 1101 - AY2019-T5: Discussion Unit 2 https://my.uopeople.edu/mod/forum/discuss.php?d=230935 4/54 color = "Blue" # I defined Blue color outside the function as showing and in order to print i t I initiate print. print ("The color outside function is " + color) def displaycolor (): color = "Red" print ("The color inside the function is " + color) [Show More]

Last updated: 10 months ago

Preview 5 out of 54 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Loading document previews for CS 1101 Programming Fundamentals - Term 5, 2018-2019CS 1101 - AY2019-T5_ Discussion Unit 2.  With answers

Loading document previews ...

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Also available in bundle (1)

Click Below to Access Bundle(s)

CS 1101 Programming Fundamentals. all terms questions and answers, practice questions with correct answers and project.

CS 1101 Programming Fundamentals. all terms questions and answers, practice questions with correct answers and project. the right A grade materials to pass.

By Professor Lynne 4 years ago

$11

13  

Reviews( 0 )

$14.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

245
0

Document information


Connected school, study & course


About the document


Uploaded On

Jun 07, 2021

Number of pages

54

Written in

All

Seller


Profile illustration for Professor Lynne
Professor Lynne

Member since 4 years

372 Documents Sold

Reviews Received
34
13
4
0
4
Additional information

This document has been written for:

Uploaded

Jun 07, 2021

Downloads

 0

Views

 245

More From Professor Lynne

View all Professor Lynne's documents »

Recommended For You

Get more on CODING SOLUTION »

$14.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·