Discussion Assignment Unit5
Discussion Assignment Unit5
4 from your
textbook. Each of the following Python functions is supposed to check whether its argument
has any lowercase letters.
For each function, describe what it actually does when called with a string argument. If it does
not correctly check for lowercase letters, give an example argument that produces incorrect
results, and describe why the result is incorrect.
#1
def any_lowercase1(s):
for c in s:
if c.islower():
return True
else:
return False
#2
def any_lowercase2(s):
for c in s:
if 'c'.islower():
return 'True'
else:
return 'False'
#3
def any_lowercase3(s):
for c in s:
flag = c.islower()
return flag
#4
def any_lowercase4(s):
flag = False
for c in s:
flag = flag or c.islower()
return flag
#5
def any_lowercase5(s):
for c in s:
if not c.islower():
return False
return True
The code and its output must be explained technically whenever asked. The explanation can be
provided before or after the code, or in the form of code comments within the code. For any
descriptive type question, Your answer must be at least 150 words.
End your discussion post with one question related to programming fundamentals learned in
this unit from which your colleagues can formulate a response or generate further discussion.
Remember to post your initial response as early as possible, preferably by Sunday evening, to
allow time for you and your classmates to have a discussion.
When you use information from a learning resource, such as a textbook, be sure to credit your
source and include the URL. This is a good time to start practicing some of what you learned
about APA in UNIV 1001!
solution
Part 1
a) If you are trying to print your name, what happens if you leave out one of the
// The error "Name Error: name 'Sayile' is not defined" is shown when you try to input your
name without both quotation marks because the Python interpreter does not recognize the name
"Sayile".
// The error "Syntax Error: unterminated string literal (detected at line 1)" is shown when you try
to print your name without one of the quotation marks because the Python interpreter does not
In Python, strings are enclosed in quotation marks. When you type a string in Python, you must
always use quotation marks to surround the string. This is because the Python interpreter does
If you leave out one or both of the quotation marks, the Python interpreter will not be able to
identify the end or beginning of the string. This will cause an error.
b) What is the difference between * and ** operators in Python? Explain with the help
of an example.
The * operator is used for multiplication. For example, `5 * 3` will return the value 15.Thisis
because the ** operator is used to raise the first operand to the power of the second operand.
Hence we get the number 125 in this example I shared because the number 5 is multiplied by its
self 3 times.
// The above error is shown when I try to print the value 09 in python. In Python leading zeors
are not allowed because they can be ambiguous, therefore in order to avoid ambiguity Python3
requires that all numbers start with a non-zero digit. This then means that the number 09 is not
d) Run the commands type ('67') and type (67). What is the difference in the output
and why?
// type (67) is identified as an integer by python, this is because python identifies a whole number
as an integer.
Part 2
a) To multiply your age by 2 and display it. For example, if your age is 16, so 16 * 2 =
32 b
b) Display the name of the city, country, and continent you are living in.
c) To display the examination schedule (i.e., the starting and the ending day) of this
term.
d) Display the temperature of your country on the day the assignment is attempted by
you
I learned that when it comes to python programming, it’s not necessary to determine the Data
type. For example, when it comes to other programming languages like C, C++, if I was trying to
use an integer value I had to identify the data type in relation to the variable being used as shown
below:
Int a = 10;
Print (a)
However, what I found interesting and really amazing is that when it comes to python I didn’t
a = 10
Print(a)
References:
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
https://greenteapress.com/thinkpython2/thinkpython2.pdf
https://cfm.ehu.es/ricardo/docs/python/Learning_Python.pdf