Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
choice = int()
show_list= []
def main():
print("1. List all TV Shows")
print("2. Add a TV Show")
print("3. Delete a TV Show")
print("4. Exit")
choice = input("Please enter a number: ")
choice = int(choice)
if choice == 1:
print(show_list)
main()
elif choice == 2:
add_shows = int(input("Enter number of TV shows to add: "))
while True:2
for x in range(add_shows): #error
show = [input(("Please enter your TV Show: ").strip())]
show.append(show_list)
else:
break
main()
elif choice == 3:
remove_shows = int(input("Enter number of TV shows to delete: "))
while True:
for x in range(add_shows): #error
show = [input(("Please enter your TV Show: ").strip())]
show.append(show_list)
else:
break
main()
elif choice == 4:
print("Goodbye")
so this is the code i have so far. i am having an issue when i choose an option, do said option, and go back to select another, that it doesnt let you do it. im not sure what the error is in my for x in range() is but trinket(online python program) is running it as an error. also my list isnt working. i can do the add a show but it is not saving.
thank you any help in advance.
seems you are new to python. Your code has a lot of syntax and syntactical errors. Just take a look at the code, and try to figure out what was wrong.
show_list= []
choice = -1
while choice != 4:
print("1. List all TV Shows")
print("2. Add a TV Show")
print("3. Delete a TV Show")
print("4. Exit")
choice = input("Please enter a number: ")
choice = int(choice)
if choice == 1:
print(show_list)
elif choice == 2:
add_shows = int(input("Enter number of TV shows to add: "))
for x in range(add_shows):
show = input(("Please enter your TV Show: ").strip())
show_list.append(show)
elif choice == 3:
remove_shows = int(input("Enter number of TV shows to delete: "))
for x in range(remove_shows):
show = input(("Please enter your TV Show: ").strip())
show_list.remove(show)
elif choice == 4:
print("Goodbye")
If you have any question, feel free to ask in the comments.
PS: Don't get bothered about the downvotes. Happens.
Related
im making a quiz program where the the user can add as many questions as they want to the quiz and they can take the quiz as well. i just dont know how to print the questions individually.
questionsList = []
rightAnswersList = []
choicesList = []
while True:
option = int(input("Add questions or take the quiz? 1 or 2 respectively: "))
if option == 1:
# adds a question to questionsList and choices to choicesList and answers to rightAnswersList
elif option == 2:
# prints question1 --> choices --> asks answer then it loops so question2 and its choices will now be printed
I'm not sure what you want, but this fulfills the bare minimum of what your comments ask:
questionsList = []
rightAnswersList = []
choicesList = []
while True:
option = int(input("Add questions or take the quiz? 1 or 2 respectively: "))
if option == 1:
questionsList.append(input("Enter question: "))
choices = []
while True:
choice = input("Enter answer choice or enter 'q' to exit: ")
if choice == "q":
break
choices.append(choice)
choicesList.append(choices)
rightAnswersList.append(input("Enter answer: "))
elif option == 2:
for i in range(len(questionsList)):
print(questionsList[i])
print("Choices:\n" + "\n".join(choicesList[i]))
answer = input("Enter your answer: ")
print("Your answer is: " + answer)
print("Correct answer is: " + rightAnswersList[i])
You may need to add additional code to filter user input or check user answers.
I am trying to conduct a very basic mini quiz but I keep running into an issue where only my else statement is being fulfilled & I'm not sure as to why?
userSleep = [input("Please enter 1 or 2 to answer the question. ")]
if userSleep == 2:
print("Thank you for your answer")
time.sleep(1)
print("What would you say stops you from getting more sleep?")
print("[1.] Social Media")
time.sleep(.25)
print("[2.] On-demand TV services (i.e Netflix, Crunchyroll, YouTube etc.)")
time.sleep(.25)
print("[3.] Medically diagnosed insomnia")
time.sleep(.25)
print("[4.] School assignments/coursework")
time.sleep(.25)
print("[5.] Other")
time.sleep(.5)
userHabits = [input("Please enter a number corresponding one of the options above to answer the question. ")]
print("Thank you for your answer")
time.sleep(1)
break
clear()
elif userSleep == 1:
print("Thank you for your answer")
time.sleep(1)
break
clear()
else:
print("Please input either a 1 or 2")```
I'm using Python 2.7
Change userSleep = [input("Please enter 1 or 2 to answer the question. ")] to userSleep = int(input("Please enter 1 or 2 to answer the question. "))
i am trying to learn about the while loop and am trying to build something with it.
i have a function that will hold a choice that the user will make but every time i run it the script is asking for the input twice..
can someone please explain to me what is wrong with my code?
thanks in advance!! :)
code:
def choice():
choice = int(input("what is your choice? "))
valid_choice = False
while not valid_choice:
if choice >= 1 and choice <= 4:
return choice
valid_choice = True
else:
print("Please enter a valid response..")
choice = int(input("what is your choice? "))
def beginning():
while True:
display_menu()
choose = choice()
if choose == 1: print("Your status")
print(Michael.status())
print()
print("Banks's status:")
print(Prod.status()) elif choose == 2: withraw = float(input("How much money do you want to withraw from the bank?: "))
Prod.withrawl(withraw)
Michael.withraw(withraw)
You were calling choice twice
I'm attempting to write an escape room game in Python.
When I run the code with pycharm the process ends with "process finished with exit code 0."
Is there something wrong in the defining of the functions?
Here is my code (its a bit lengthy):
choice = None
def main_choice():
print("1. Examine door")
print("2. Examine painting")
print("3. Examine desk")
print("4. Examine bookshelf")
choice == input("Make your choice: ")
def door():
print("1. Try to open door")
print("2. Take a closer look")
print("3. Go back to where you were.")
door_choice = input("What now? ")
if door_choice == "1":
print("The door is too heavy to open with your bare hands.")
door()
if door_choice == "2":
print("There is a red light above the door, but it seems to have no purpose.")
print("You notice a 9 key keypad next to the door. It looks like it will accept a 3 digit code.")
keypad_code = input("Would you like to enter a code?").lower
if keypad_code == " yes":
guess = input("ENTER CODE: ")
if guess == complete_key:
print("The light turns green and you hear the sound of a mechanical lock unlocking. The door opens.")
print("YOU WIN!!!")
if guess != complete_key:
print("Wrong code.")
main_choice()
if door_choice == "3":
main_choice()
else:
print("You didn't answer")
main_choice()
if choice == "1":
print("You walk to the door")
door()
I think that it might be the last "if" statement, but I'm not positive.
You need to change choice == input("Make your choice: ") to choice = input("Make your choice: ") in your main_choice function:
def main_choice():
print("1. Examine door")
print("2. Examine painting")
print("3. Examine desk")
print("4. Examine bookshelf")
choice = input("Make your choice: ")
Otherwise the choice variable will still be None and if choice == "1": will always be False.
You should write:
choice = input("Make you choice: ")
rather than:
choice == input("Make you choice: ")
Double equals signs return a boolean rather than changing a value.
I'm writing this program that is basically a limited calculator. I'm trying to make it so that if the user enters let's say "Power" instead of the number 1 for the desired mode, it prints out "Invalid selection". The same goes if they attempt to write "Quadratics" instead of 2 and so on for the rest.
#CALCULATOR
print("MY CALCULATOR")
print("1. Powers")
print("2. Quadratics")
print("3. Percents")
print("4. Basic Ops")
choice = int(input("Please enter your desired mode: "))
if choice == 1:
base = int(input("Enter the base: "))
exponent = int(input("Enter the exponent: "))
power = base**exponent
if choice == 2:
print("Please enter the values for A/B/C: ")
a = int(input("A: "))
b = int(input("B: "))
c = int(input("C: "))
I tried doing:
if choice not == 1:
print("Invalid Selection")
and
if choice not 1:
print("Invalid Selection")
but they don't seem to work. If you could please tell me what I am doing wrong. Thank you.
not is not a function. It is an operator.
The correct usage is to put it before an expression:
if not (choice == 1):
However in this case, it's much better to use != (not equal) instead:
if choice != 1: