May-09-2018, 11:18 AM
(This post was last modified: May-09-2018, 11:18 AM by Tamimi1982.)
Hello Pythoners
In my last assignment I received the following task.
Step 1:
I need to write a code that ask the user to input either 'A' or 'T'. Any other input means the user will receive a notification that their input is invalid and the input message please insert 'A' or 'T' appears again.
step 2:
if the user insert 'A' or 'a' or 't' or 'T', a new input ask the user to insert an integer or 'Q'. The program will keep accumulating the integers inserted until 'q' or 'Q' is inserted. any other input than integer the user will be notified that the input is invalid and it will ask them again to insert an integer or 'Q' Then
Step 3:
if the user inserted A in step 1, the output will show all the inserted integers in separate lines and at the end the total, example:
4
5
Total
9
if the user inserted T in step 2, the output will show the total only, example:
Total
9
Note:
Only these keywords are allowed:
if
elif
while
input
print
else
def
Now I did not pass the assignment but I still don't know why I keep getting it wrong.
Here is my code:
In my last assignment I received the following task.
Step 1:
I need to write a code that ask the user to input either 'A' or 'T'. Any other input means the user will receive a notification that their input is invalid and the input message please insert 'A' or 'T' appears again.
step 2:
if the user insert 'A' or 'a' or 't' or 'T', a new input ask the user to insert an integer or 'Q'. The program will keep accumulating the integers inserted until 'q' or 'Q' is inserted. any other input than integer the user will be notified that the input is invalid and it will ask them again to insert an integer or 'Q' Then
Step 3:
if the user inserted A in step 1, the output will show all the inserted integers in separate lines and at the end the total, example:
4
5
Total
9
if the user inserted T in step 2, the output will show the total only, example:
Total
9
Note:
Only these keywords are allowed:
if
elif
while
input
else
def
Now I did not pass the assignment but I still don't know why I keep getting it wrong.
Here is my code:
items = 0 def omode(): mode = input('Please enter "A" or "T" ') return mode if omode().isupper() == "T": items = input('Please input an integer or Q ') while items.isdigit() == True: totala = int(items) + int(items) items = input('Please input an integer or Q ') if items.isdigit() == False: if str(items).isupper() == "Q": print("items \n", totala) else: print(items,'is an invalid input') items = input('Please input an integer ') elif omode() == "A": items = input('Please input an integer or Q ') while items.isdigit() == True: totala = int(items) + int(items) items = input('Please input an integer or Q ') print(items) if items.isdigit() == False: if str(items).isupper() == "Q": print (totala) else: print(items,'is an invalid input') itmes = input('Please input an integer or Q ') else: while omode() != "T" or omode() != "A": print("This is an ivalid input, please insert A or T") omode()