+ 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")
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
+ 2
write whole code inside:
while True loop to loop it infinitely
+ 2
You can try to use dict instead of using "if"
+ 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))
+ 1
File "<ipython-input-1-f03332dc0c80>", line 5 while not grades.get(grade:=input("enter your grade: "), False): ^ SyntaxError: invalid syntax
+ 1
Fine
+ 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;
0
#Bob_Li🔥🔥🔥🔥
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
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?