[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Learning python, Having some issues

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 9
Thread images: 1

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?
Thread posts: 9
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.