I'm new to coding and I'm taking some basic learning, right now I'm just trying to formulate something pretty simple and I'm having trouble.
i don't have notepad since I'm using mac, so I'm using IDLE but its not working so great
When have
A = input('how many cards do you have?')
print('you have a A card deck')
B = input('how many cards are you taking out')
print('you took out B cards')
in the print it doesn't actually write the input number, its just typing the letter B
then it won't convert it to float! i can finish it.
is there something I'm missing? I'm sorry if this isn't where I'm supposed to post, I'm new and just trying to figure things out.
When using quotes the print will interprete the who argument as a string. It's desplaying A and B because your telling it to.
You need to keep the variable outside of the quotes via +
Print('Wordwordword' + A + 'morewords')
>>59028054
You're putting in "B" in the string literal. You want to break up your string so that you're referring to the B variable.
Something like:
print('You took out ' + B + ' cards')
Also, try using the float() function to convert a number.
>>59028079
Might as well just cast them as integers if your counting in whole numbers.
B=int(B) turns the string B into and into a int.
You can also short had it to int(B)==
(I think it's been a while)
>>59028072
>>59028079
i just tried
A = input('how many cards do you have?')
print('you have a ' +A+ 'card deck')
B = input('how many cards are you taking out')
print('you took out ' +B+ ' cards')
A_Value = float('A')
B_Value = float('B')
Deck = ('A-B')
print('Deck')
and it didnt seem to work, it printed out
'you took out ' +B+ ' cards'
so i added the ' to either side and it came out with
cannot concatenate 'str' and 'int' objects
thank you very much for your help by the way
>>59028127
I think it's actually supposed to be commas instead of + in python3 print.
You might also look up the format() function, which is the best way to format strings
>>59028127
Do this instead.
A = input('How many cards do you have?')
print('You have a {0} card deck '.format(A))
B = input('how many cards are you taking out?')
print('you took out {0} cards'.format(B))
A_VALUE = float(A)
B_VALUE = float(B)
Deck = (A_VALUE-B_VALUE)
print(Deck)
>>59028147
Thank you! i got past that part, its finally displaying the number!
Now it won't convert to either float or int, but thank you very much! I'm going to keep going to see what i can do about that.
thank you everyone! you helped me complete my first line of code other than the basic hello world.
you gotta start somewhere right?