Please don't hate me if something like this has been asked, I couldn't find a similar problem. I'm learning python, and I'm trying to get a small piece of code to work in IDLE shell 3.9.7 like this
>>> mark=int(input("enter mark"))
if mark>=90:
print("excellent")
elif mark<90 and mark>=75:
print("good")
elif mark<75 and mark>=40:
print("average")
else:
print("fail")
with the idea that you enter the mark, then it prints one of the statements without having to run the input code then the if/elif/else statements afterwards (I want to have all this code, press enter and then get the desired input/output without running the if/else statements separately.) However, when I run the code, I enter the mark and nothing happens. I've tried different indentation and putting the input bit at the end, but it just asks for the mark and then nothing happens. I'm not sure what I'm doing wrong, as the app that I'm using to learn has it parsed exactly like this. Appreciate any help.
CodePudding user response:
Try this it should work just had to put it in a for loop
while True:
mark=int(input("enter mark: "))
if mark>=90:
print("excellent")
elif mark<90 and mark>=75:
print("good")
elif mark<75 and mark>=40:
print("average")
else:
print("fail")
CodePudding user response:
(I want to have all this code, press enter and then get the desired input/output without running the if/else statements separately
Probably you want a function
, like this:
def foo(mark: str) -> None:
if mark>=90:
print("excellent")
elif mark<90 and mark>=75:
print("good")
elif mark<75 and mark>=40:
print("average")
else:
print("fail")
that you can call this way in the shell:
>>> foo(int(input("Enter your mark: ")))
10
fail