0% found this document useful (0 votes)
2 views7 pages

Discussion Assignment Unit5

The document discusses a Unit 5 Discussion Forum assignment focused on Python functions that check for lowercase letters in strings. It provides examples of five functions, explaining their behaviors and identifying incorrect implementations. Additionally, it covers programming fundamentals such as string handling, operators, and data types in Python, along with references for further reading.

Uploaded by

SAYILE JAMES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Discussion Assignment Unit5

The document discusses a Unit 5 Discussion Forum assignment focused on Python functions that check for lowercase letters in strings. It provides examples of five functions, explaining their behaviors and identifying incorrect implementations. Additionally, it covers programming fundamentals such as string handling, operators, and data types in Python, along with references for further reading.

Uploaded by

SAYILE JAMES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Welcome to the Unit 5 Discussion Forum! This assignment is based on Exercise 8.

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

quotation marks or both, and why?

>>> print (sayile)

// 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

know where the string ends.

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

not know where the string starts and ends.

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 multiply the two operands together.


The** operator is used for exponentiation. For example, `5 ** 3` will return the value 125.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.

c) In Python, is it possible to display an integer like 09? Justify your answer

>>> print (09)

// 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

valid in Python and must be written as 9 or 0o9.

d) Run the commands type ('67') and type (67). What is the difference in the output

and why?

>>> type ('67')


// type (‘67’) is identified as a string by python, this is because python Identifies any character or

digit that is with quotation marks as a string.

>>> type (67)

// 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

have to state the data type, as show below:

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

Mark Lutz, Copyright © 2009, Fourth Edition. Learning Python pdf.

https://cfm.ehu.es/ricardo/docs/python/Learning_Python.pdf

You might also like