Homework:
Create a dictionary that corresponds a letter to a set of numbers for grades (A = 100-90, B = 89-80, etc). Take user input for a letter and then print the appropriate grade range.
Write a function to reverse all the characters of a string.
Write a function that takes a list and multiplies all the elements together.
Resources:
Class slides: https://docs.google.com/presentation/d/1YP329tgCan7mXNj7ZcnjHDx UKm9ccPsvHKt1mss6ylE/edit?usp=sharing
Code: https://replit.com/join/muzkblsbjr-shravyas
Coding platform: replit.com
Post your answers as a comment! I will post the solution before next class.
You can always email us at shravyassathish@gmail.com (mentor) or kingericwu@gmail.com (TA) or message us on Discord if you have any questions about the homework or what we covered in class.
teacherWeapon = {"A": "90 - 100, good", "B": "80 - 90, fair", "C": "70 - 80, poor", "D": "60 - 70, bad", "F": "0 - 60, sad"}
embarrassingScore = input("What was your most recent test score? ")
print(teacherWeapon.get(embarrassingScore))
def stringReverse(s):
x = ''
y = []
for i in range(len(s)):
y.insert(0, s[i])
for i in y:
x = x + i
return x
def listMultiply(list279):
x = 1
for i in list279:
x *= i
return x
Solution:
Part 1:
dict={"A":"100-90","B":"89-80","C":"79-70","D":"69-60","F":"59-0"}
x=input()
print(dict.get(x))
Part 2:
chars=""
for i in reversed(input()):
chars=chars+i
print(chars)
Part 3:
num=1
x=1
while x!=0:
num=num*x
x=int(input())
print(num)
grades = {"A":"100 - 90","B":"89 - 80","C":"79 - 70","D":"69 - 60","F":"59 - 0"}
i = input("What is the grade? ")
print(grades.get(i))
string = input("Input a string: ")
x = ''
for i in range(len(string)-1, -1, -1):
x = x + string[i]
print(x)
list1 = []
a = 1
while int(a) != -1:
list1.append(int(a))
a = input("Give me a number to multiply. If you are done, type in -1: ")
x = 1
for i in list1:
x = x*i
print(x)
Part 1:
grades = {"A":"90%-100%", "B":"80%-89%", "C":"70%-79%", "D":"60%-69%", "F":"0%-59%"}
letterGrade = input("Input letter grade: ")
print(grades.get(letterGrade))
Part 2:
def reverseStr(string):
output = ""
for i in range(len(string)-1, -1, -1):
output += string[i]
return output
print(reverseStr("reverse this message"))
Part 3:
def multiplyList(list):
product = 1
for i in list:
product*=i
return product
print(multiplyList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
# 1
gradeDic={"A":"100-90","B":"89-90","C":
"79-70","D":"69-60","F":"59-0"}
inputGrade = input("Please enter the grade letter:")
print(gradeDic.get(inputGrade))
#2
def reverse(word):
list1 = list(word)
ans=""
for i in range(len(list1)-1,-1, -1):
ans += list1[i]
return ans
res= reverse("Hello World")
print("result ="+res)
#3
def multiplyNums(list1):
res = 1
for i in list1:
res *= i
return res
inputList = input("please enter a list of numbers:").split()
for i in range(len(inputList)):
inputList[i]= int(inputList[i])
productNums= multiplyNums(inputList)
print("product of all numbers="+str(productNums))