Home > Mobile >  Add yes/no confirmation
Add yes/no confirmation

Time:08-22

im new in python and its my first new code and i have problem with my input confirmation how can say to python if some one use y continue code and run it?

import datetime
import random
import time

print('Enter your name:')
x = input()
print('Hello, '   x) 
throw_start = input("Want to start triger C4!?(y/n)\n")
if throw_start == 'y':
        ****??????** = True**
    else:
        quit()
add =  [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59]
for i in range(3):
    right_this_minute = datetime.today() .minute
    today = datetime.today()
    today_persian = jdatetime.datetime.now()
    print("Time is:",today)
    print("Persian Time is:",today_persian)
    if right_this_minute in add:
        print ("Number is ODD")
    else:
        print("Number is not ODD")
    w8_time = random.randint(1,10)
    for i in range(w8_time):
        print(str(w8_time - i)   " Second to Blowup")
        time.sleep(1)
    print("BOOOOOOOOM,Lets go next ")
    time.sleep(5)

CodePudding user response:

I think that simplest solution for you would be to just put pass in that if condition.

if throw_start == 'y':
    pass
else:
    quit()

So that if answer is 'y' just continue and if answer is anything else quit()

or you can also negate your condition, so quit if answer is not 'y'

if throw_start != 'y':
        quit()

CodePudding user response:

you have problem with indentation you also placed the content of the if statement in the wrong place
the following solution should solve your current problem

import datetime

import random import time

x = input('Enter your name:')
   print('Hello, '   x) 
   throw_start = input("Want to start triger C4!?(y/n)\n")
   if throw_start == 'y':
       add =  [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59]
       for i in range(3):
           right_this_minute = datetime.today() .minute
           today = datetime.today()
           today_persian = datetime.datetime.now()
           print("Time is:",today)
           print("Persian Time is:",today_persian)
           if right_this_minute in add:
               print ("Number is ODD")
           else:
               print("Number is not ODD")
           w8_time = random.randint(1,10)
           for i in range(w8_time):
               print(str(w8_time - i)   " Second to Blowup")
               time.sleep(1)
           print("BOOOOOOOOM,Lets go next ")
           time.sleep(5)
   else:
       quit()

Notice that you have another problem in this line right_this_minute = datetime.today() .minute I am not sure what you are trying to do but you better learn more about python's datetime library

CodePudding user response:

the essention part is this:

if throw_start == 'y':
    pass
else:
    exit()

but there were so many errors in the code (imports / typos), that it needed to be re-written to work. also note, that the code does not appear to stop (infnite loop).

Anyway, here is the full code

import datetime
import random
import time


print('Enter your name:')
x = input()
print('Hello, '   x) 
throw_start = input("Want to start triger C4!?(y/n)\n")
if throw_start == 'y':
    pass
else:
    exit()
add =  [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59]
for i in range(3):
    right_this_minute = datetime.datetime.today() .minute
    today = datetime.datetime.today()
    today_persian = datetime.datetime.now()
    print("Time is:",today)
    print("Persian Time is:",today_persian)
    if right_this_minute in add:
        print ("Number is ODD")
    else:
        print("Number is not ODD")
    w8_time = random.randint(1,10)
    for i in range(w8_time):
        print(str(w8_time - i)   " Second to Blowup")
        time.sleep(1)
    print("BOOOOOOOOM,Lets go next ")
    time.sleep(5)
  • Related