S
S
Shikki2212020-04-27 18:25:44
Python
Shikki221, 2020-04-27 18:25:44

A program that asks you to enter anything and after entering it gives 'Ok', but if you just press Enter without entering anything, the program will stop. How to do?

Can't get the desired result. Enter is recognized as a letter.

z = input ("Введите что-нибудь:  ")

#число
if type (z) == int:
   print ("Ok")

#дробное число
elif type (z) == float:
   print ("Ok")

#текст
elif type (z) == str:
   print ("Ok")

#Enter
elif

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-04-27
@shikki221

while input('Введите что-нибудь: '):
    print('Ok')

S
Sergey Karbivnichy, 2020-04-27
@hottabxp

To test z for type, you must first cast z to the correct type. And you will always have a string in the z variable (until you manually convert it to another type)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question