Course Hero Logo

cs1101 discussion forum unit 2.docx - 1. > def...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 3 pages.

1.>>>def greeting_user(name):print(f'Hi {name}')>>> greeting_user('Kayizzi')Hi Kayizzi(name) is the parameter('Kayizzi') is the argument2.Using a value argumentWe use the quotation marks to define the value>>> greeting_user('Richard')Hi RichardUsing a variable argumentWe don’t use the quotation marks because the variableKis already defined>>> K='Kayizzi'>>> R='Richard'>>> greeting_user(K)Hi KayizziUsing an expression argumentWe don’t use the quotation marks because the variablesKandRare already defined>>> greeting_user(K + R)Hi KayizziRichard3. A function with a local variable ‘age>>> def user_age(number):age=number
print(f"Kayizzi is {age} years old")>>> user_age(21)Kayizzi is 21 years oldWhen I try to use the local variable ‘age’ outside the function>>> print(age)Traceback (most recent call last):File "<pyshell#8>", line 1, in <module>print(age)NameError: name 'age' is not definedWhen you create a variable inside a function, it islocal, which means that it only exists inside thefunction.When user_age terminates, the variable

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 3 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Summer
Professor
SHEBAH
Tags
variable argument, Kayizzi

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture