12/09/2023, 20:16 BANA200Week2.
ipynb - Colaboratory
Exercise 1: Lottery Winning Number Checking
You have been asked to create a program with the following functions:
Ask user for their lottery ticket number. If the input matches the winning number, 8918354118, then print a message, “Congratulations,
you are the winner!”
If the input does not match the winning number, then print, “Sorry, you are not the winner.”
Print “Thank you for using my system!” to all users.
1 # Please enter your code below
Exercise 2: Letter Grade Conversion
Ask Professor to enter a score between 0 and 100. If the score is out of range, print an error message. If the score is between 0 and 100, print a
grade using the following table:
if >=90: A
if >=80: B
if >=70: C
if <70: F
1 # How would you debug the following code?
2
3 score = input("Please enter a score: ")
4 if score >= 0 or score <= 100
5 if score >= 90:
6 lettergrade = 'A'
7 elif score >= 80:
8 lettergrade = 'B'
9 elif score >= 70:
10 lettergrade = 'C'
11 elif score >= 60:
12 lettergrade = 'D'
13 else
14 lettergrade = 'F'
15 print(f"The letter grade is: {lettergrade}.")
16 else
17 print('Bad Score!')
18
1 # Using for loop to count the number of items in a list: [3, 41, 12, 9, 74, 15]
2 count = 0
3 for itervar in [3, 41, 12, 9, 74, 15]:
4 count = count + 1
5 print('Count: ', count)
Count: 6
1 # Using for loop to compute the sum of all numbers in the list
2 mysum = 0
3 for itervar in [3, 41, 12, 9, 74, 15]:
4 mysum = mysum + itervar
5 print("Sum is : ", mysum)
Sum is : 154
1 # Using for loop to find the largest/smallest value in the list
2 def is_largest(i):
3 input: i is largest int
4 print("leagest number: ")
5 return i
File "<ipython-input-15-00cfe3b8e629>", line 3
input: i is largest int
^
SyntaxError: invalid syntax
SEARCH STACK OVERFLOW
1 # Functions
2 def is_even( i):
3 """
4 Input: i, a positive int
5 Returns True if i is even, otherwise False
https://colab.research.google.com/drive/1VluN0xmP5qa2hKpsn885ieMBJNN665qI#scrollTo=tUKq3zz3LeDW&printMode=true 1/2
12/09/2023, 20:16 BANA200Week2.ipynb - Colaboratory
6 """
7 print("This is an even number?")
8 return i%2 == 0
9
10
11 x=3
12 is_even(x)
13
Colab paid products - Cancel contracts here
https://colab.research.google.com/drive/1VluN0xmP5qa2hKpsn885ieMBJNN665qI#scrollTo=tUKq3zz3LeDW&printMode=true 2/2