I am doing a small console program. You input the data and then program puts it in .txt file. The data is: Country Year of birth Month of birth Day of birth Real name Nickname
I decided to do a definition for every variable, so if user types an integer in "Country" it gives him a warning and vice versa. Here is the code:
countryU = input('Страна проживания ')
yearU = input('Год рождения ')
monthU = input('Месяц рождения (его порядковый номер) ')
dayU = input('День рождения ')
nameU = input('Имя ')
nicknameU = input('Никнейм ')
aaaaa = 5
from random import *
u = randint(1,1000000000000)
uinfoname = str(u) + '.txt'
if type(countryU) == str:
if type(yearU) == int:
if type(monthU) == int:
if type(dayU) == int:
if type(nameU) == str:
if type(nicknameU) == str:
if countryU == '':
print('Вы ввели не все данные! Перезапустите программу и введите все.')
input('Press any key to exit...')
else:
if yearU == '':
print('Вы ввели не все данные! Перезапустите программу и введите все.')
input('Press any key to exit...')
else:
if monthU == '':
print('Вы ввели не все данные! Перезапустите программу и введите все.')
input('Press any key to exit...')
else:
if dayU == '':
print('Вы ввели не все данные! Перезапустите программу и введите все.')
input('Press any key to exit...')
else:
if nameU == '':
print('Вы ввели не все данные! Перезапустите программу и введите все.')
input('Press any key to exit...')
else:
if nicknameU == '':
print('Вы ввели не все данные! Перезапустите программу и введите все.')
input('Press any key to exit...')
else:
if (len(str(nicknameU)) < aaaaa):
print('Твой никнейм недостаточно длинный! (минимум 5 символов) Перезагрузите программу и введите все правильно.')
input('Press any key to exit...')
else:
print('Вы -', nameU, 'из страны', countryU, '')
print('Ваша дата рождения: месяц', monthU, 'число', dayU, 'год', yearU, '')
print('Ваш никнейм на сайте -', nicknameU, '.')
print('Приятного времяпрепровождения!')
output = open(uinfoname, 'x')
print(countryU, file=output)
print(yearU, file=output)
print(monthU, file=output)
print(dayU, file=output)
print(nameU, file=output)
print(nicknameU, file=output)
output.close()
input('Press any key to exit...')
else:
print('Никнейм не должен содержать специальные символы или цифры!')
input('Press any key to exit...')
else:
print('Имя не должно содержать специальные символы или цифры!')
input('Press any key to exit...')
else:
print('День вашего рождения является числом!')
input('Press any key to exit...')
else:
print('Месяц вашего рождения является числом!')
input('Press any key to exit...')
else:
print('Год вашего рождения является числом!') #pay attention to this string, this is the problem
input('Press any key to exit...')
else:
print('Название вашей страны не может содержать специальные символы или цифры! (Если название вашей страны все-таки их содержит, напишите название без них.')
input('Press any key to exit...')
Don't mind, I am Russian and I use Russian language. Well, to the problem: When I run the program and type everything correctly (integer to integer, string to string), it says: Год вашего рождения является числом! (the problem string) It means "Your year of birth should be a number!" And even if I type the country incorrectly (integer), it says the same. So whatever I type, it gives me that string. I also used isinstance, but it is much worse here. Please help me!
type(countryU)will always bestr, becauseinputalways returns astr.if/elsestatements.elifstatements instead of nestedelse if, to make the code more readable.