Professional Documents
Culture Documents
Lecture 2.2-After-Large
Lecture 2.2-After-Large
• Today
• Last Time
• Python • In-class Exercises
• Data types • Software Engineering
• Variable • Piazza Challenges
• Operators
• Input function
• Reading
• cspy ch. 1 & 2
• String constants
• Anything inside of single quotes or double quotes, and + for strings is concatenation
>>> a = 1
>>> b = 3
>>> c = 6
>>> d = a + (b + c) * 3
>>> print(d-2)
1. 14
2. 26
3. 28
4. 33
CMPT 120, Spring 2023, Mohammad Tayebi 4
In-class Exercise 9
>>> a = 2
>>> b = 3
>>> c = 1
>>> a = b + a**2 * 3 - (b%c*a)
>>> print(a)
1. 10
2. 12
3. 15
4. 23
• Write a program to ask the user what day of the week is today and
print the answer.
#this is a program to ask and print what the day of the week is today.
day = input ("What day of the week is today?")
print("Today is " + day)
• Write a program to ask the user first name, last name and country and
print this information in the following format:
Justin Trudeau is from Canada.
Alternative way
print(first_name, last_name, " is from " + country + ".")
CMPT 120, Spring 2023, Mohammad Tayebi 9
In-class Exercise 13
• Write a program to take number of minutes from the user and covert
it to seconds.
• Write a program to take number of minutes and hours from the user
and covert the total it to seconds.
• Write a program to take number of days, hours and minutes from the
user and convert the total time to seconds. We used extra parenthesis only
to improve the code readability.