Docsity

Python Operators and Conditional Statements, Schemes and Mind Maps of Computer science

Toggle sidebar
bg1
Questions
Not yet graded
1. Place the correct operators in#, with the wordTruewritten for each
line. Note that==checks for equality.
1
print(16 # 7 == 2)
2
print((7 # 2) # 10 == 35)
3
print(2 # 4 == 0.5)
4
print(5 # 2 # 3 == -1)
5
print(3 # 2 # 1 == 7)
6
2. Consider that the days are represented
asSunday1,Monday2,Tuesday3, etc. Accept thattodayisSunday.
Write the code below to show which day will be82daysfrom now.
(the program must print the6value that representsFriday)
1
3. Accept that your vehicle
goes40miles"per"gallonandthe"cost"of"one"gallonof gas is$
3.65. Write the code below to
printhow"many"miles"you"can"drivewith a$ 25budget. The program
should print the value273.97.
4. Suppose you wait270 minutesfor a meeting (You should get this
value usinginput()function). Write the code below to
printhow"many"hours"and"minutesyou expect intotal. Remember that
it is60 minutesinan"hour. The program should also
print30after4.0.
1
pf3
pf4
pf5

Partial preview of the text

Download Python Operators and Conditional Statements and more Schemes and Mind Maps Computer science in PDF only on Docsity!

Questions

Not yet graded

  1. Place the correct operators in #, with the word True written for each line. Note that == checks for equality. 1 print( 16 # 7 == 2) 2 print(( 7 # 2) # 10 == 35) 3 print( 2 # 4 == 0.5) 4 print( 5 # 2 # 3 == -1) 5 print( 3 # 2 # 1 == 7) 6
  2. Consider that the days are represented as Sunday 1 , Monday 2 , Tuesday 3 , etc. Accept that today is Sunday. Write the code below to show which day will be 82 days from now. (the program must print the 6 value that represents Friday) 1
  3. Accept that your vehicle goes 40 miles per gallon and the cost of one gallon of gas is $ 3.65. Write the code below to print how many miles you can drive with a $ 25 budget. The program should print the value 273..
  4. Suppose you wait 270 minutes for a meeting (You should get this value using input() function). Write the code below to print how many hours and minutes you expect in total. Remember that it is 60 minutes in an hour. The program should also print 30 after 4.. 1
  1. A car consumes fuel at the rate of 23 mpg (23 miles per gallon
    • milepergallon). Someone fills the car with 15 gallons of fuel and moves 112 miles. Write the code below to determine how many gallons of fuel remain. The answer should be 10..
  2. One projectile travels at a speed of 25 m / s. Write the code that determines how many seconds it will go 111 m ahead. (Your program should print 4.44 seconds as a result) (Use input() function to assign values to the variables!)

Not yet graded

  1. Write a program that takes first name, last name and age of the user as an input and prints out the result as in the example below.
  2. Example Output:
  3. Hi, my name is James Bond! I'm 52 years old.
  4. Square of 5 is 25 and cube of 2 is 8. When we add this numbers to each others, we get 33. 2
  5. Fix 5 errors in the following code to set price to 1.45 if weight is less than 1 and otherwise set it to 1.. 1 weight = 0. 2 if weight < 1 3 price = 1. 4 else 5 price = 1. 6 total = weight * price

13

  1. Fix the errors in the code and add statements to the code, so that if the user gives a number less than 5 , you ask for the input again , and have another set of decision statements based off if the number is greater than, less than, or equal to 3. 1 user = input("Give me a number") 2 number = int(user) 3 if number < 5 : 4 user2 = 5 number2 = int(user2) 6 if 7 print("I love CS") 8 elif 9 print("CS is the best") 10 else: 11 print("I like CS better than food") 12 else: 13 print("Who else loves CS?") 14
  2. Fix the code so that it prints only 1 thing for each age group and uses elif and else. 1 age = 10 2 if age >= 18 : 3 print("adult") 4 if age < 18 : 5 print("teen") 6

if age < 13 : 7 print("pre-teen") 8 if age < 10 : 9 print("kid") 10 if age < 5 : 11 print("toddler") 12 if age < 2 : 13 print("baby") 14