r/pythonhelp • u/Richard_Rickson • Jul 02 '22
Python assistance needed PLEASE!
So, I have been getting into python recently as my first real dive into coding(/programming idrk feel free to correct), and I have this bit of code..
----------
print('How many bois you got in your pocket?')
dolla = input()
A = 0.01
w = 0
T = 0.05
x = 0
F = 0.10
y = 0
G = 0.25
z = 0
if[dolla > G]:
z + 1
else:
if[dolla > F]:
y + 1
else:
if[dolla > T]:
x + 1
else:
w + 1
print('Your dolla = ' + w + " Andrew, " + x + ' Thomas, ' +
y + ' Franklin, and ' + z + ' Georgies.')
if{dolla >= 1}:
print(' Congrats on having a masive cock!')
else:
(" I'm so sorry for your accident involving your weener!")
----------
It shows no errors just sitting in Visual Studio Code, but shows this error when I enter "20"(no quotes) into the input box:
TypeError: '>' not supported between instances of 'str' and 'float'
I have tried a few things so far, but have not had any luck in fixing this error..
PLZ HLP,
-RR
1
u/Obed2621 Jul 02 '22 edited Jul 03 '22
dolla = float(input(‘How many bois you got in your pocket?’))
w = x = y = z = 0
A = 0.01
T = 0.05
F = 0.10
G = 0.25
if dolla > G:
z += 1
else:
if dolla > F:
y += 1
else:
if dolla > T:
x += 1
else:
w += 1
print(f’Your dolla = {w} Andrew, {x} Thomas, {y} Franklin, and {z} Georgies.’)
if dolla >=1:
print(‘Congrats on having a massive c!’)
else:
print(« im so sorry for your accident involving your weener! »)As said by wolfbait, you need to convert the input to float, because input always return a string. Secondly doing x + 1 Wont change x,
You need to do x += 1 Or do this; x = x + 1
1
u/FM_Studios Jul 02 '22
try adding this after the input function:
try:
dolla = float(dolla)
except:
print("Can't convert into number!")
continue #ONLY USE THIS LINE IF THE CODE IS IN A WHILE / FOR LOOP (optional but recomended)
2
u/Wolfbait115 Jul 02 '22
Input returns a string. You need to convert it to float with
float(dolla).