+ 1

How do you loop this? Can you write this simplified?

How do you loop this? Can you write this simplified? # -*- coding: utf-8 -*- """ Created on Wed Oct 19 15:11:16 @author: kudoryi """ grade=input("enter your grade:") if grade== "A": print("excellent") elif grade=="B" : print("very good") elif grade=="C" : print(" good") elif grade=="D" : print("fair") elif grade=="E" : print("pass") elif grade=="F" : print("FAIL") else: print("ENTER YOUR GRADE")

2nd Nov 2022, 7:04 AM
Yeah🤗
10 Answers
+ 1
while True: try:print({'A':'excellent', 'B':'very good', 'C':'good', 'D':'fair', 'E':'pass', 'F':'fail'}[input()]) except:break This might be enough for now. I hope this is what you're looking for
2nd Nov 2022, 1:57 PM
Random
Random - avatar
+ 2
write whole code inside: while True loop to loop it infinitely
2nd Nov 2022, 7:25 AM
Random
Random - avatar
+ 2
You can try to use dict instead of using "if"
2nd Nov 2022, 9:53 AM
Danila Khaminets
Danila Khaminets - avatar
+ 1
#Yeah🤗 very weird while syntax, but it works. dictionary as switch, walrus operator, dict.get(), ellipsis(...) grades = {'A':'excellent', 'B':'very good', 'C':'good', 'D':'fair', 'E':'pass', 'F':'fail'} while not grades.get(grade:=input("enter your grade: "), False): ... print(grades.get(grade))
2nd Nov 2022, 11:50 AM
Bob_Li
Bob_Li - avatar
+ 1
File "<ipython-input-1-f03332dc0c80>", line 5 while not grades.get(grade:=input("enter your grade: "), False): ^ SyntaxError: invalid syntax
2nd Nov 2022, 1:17 PM
Yeah🤗
+ 1
Fine
2nd Nov 2022, 3:51 PM
Asim Farheen ⭐⭐🤺👿👿
Asim  Farheen ⭐⭐🤺👿👿 - avatar
+ 1
* { padding: 0; margin: 0; -webkit-box-sizing: border-box; box-sizing: border-box; font-family: "Poppins", sans-serif; } body { background-color: #fec04f; } .wrapper { width: 31.25em; position: absolute; -webkit-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); top: 50%; left: 50%; } .container { height: 31.25em; width: 100%; background-color: #151515; position: relative; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center; -ms-flex-align: center; align-items: center; -ms-flex-pack: distribute; justify-content: space-around; -webkit-box-orient: vertical; -webkit-box-direction: normal; -ms-flex-direction: column;
4th Nov 2022, 1:15 AM
Shihavul Islam
Shihavul Islam - avatar
0
#Bob_Li🔥🔥🔥🔥
2nd Nov 2022, 1:07 PM
Yeah🤗
0
Yeah🤗 older python versions might choke on that...😁 Here is a more standard way. you can comment out the break if you don't want it to end. grades = {'A':'excellent', 'B':'very good', 'C':'good', 'D':'fair', 'E':'pass', 'F':'fail'} while True: grade = input("enter your grade: ") if grades.get(grade, None): print(grades.get(grade)) break
2nd Nov 2022, 1:19 PM
Bob_Li
Bob_Li - avatar
0
I'm interesting in computer, but I don't know the programing language I should take first because I don't I understand their purpose/ use, please can you tell me at least two or three programing language use and I can choose to learn one?
3rd Nov 2022, 7:51 AM
Duol Kang