Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,207,443 members, 7,999,036 topics. Date: Sunday, 10 November 2024 at 03:23 PM |
Nairaland Forum / Science/Technology / Programming / Python Masters, Kindly Help Me Rectify This Python Problem. (1854 Views)
Who Can Help Out With This Python Problem? / I need assistance with this Python Problem / Can Someone Help Me With A Solution To This Python Problem (2) (3) (4)
Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 6:04pm On Oct 16, 2017 |
Hello! I have a little 'python' problem. I got stuck while trying to program a simple 'two-numbers-addition-only-calculator'. Instead of adding the two numbers, the calculator would rather join the two numbers. It treats the inputs as strings rather than as number variables. For example; 2 + 3 would print out "23" instead of 5. And 5 + 6 prints out '56' instead of 11. Here's the script print "ADDITION ONLY CALCULATOR" print "type first number here", first_number = raw_input() print "type second number here" , Second_number = raw_input() total_combination = first_number + second_number print "your answer is" , total_combination |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by michaelwilli(m): 6:08pm On Oct 16, 2017 |
Python reads the input as string, cast it to integer first. To convert to int, use int(first_number) 3 Likes |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 6:10pm On Oct 16, 2017 |
michaelwilli:Cool. I would do just that when I power on my pc. Thanks. |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by Olyboy16(m): 9:30pm On Oct 16, 2017 |
LordeCalifornia:to make a much more robust app, put your casting into exceptions. |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 9:47pm On Oct 16, 2017 |
Olyboy16:Hi! Pardon my ignorance, how exactly can I 'put my casting into exceptions' ? |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 9:49pm On Oct 16, 2017 |
michaelwilli:Great! It worked out just fine. Thanks! One more, how can I make it accept and process decimal fractions? |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by Nobody: 10:13pm On Oct 16, 2017 |
LordeCalifornia: first_number = input(" Please Enter the First Number: " ) second_number = input(" Please Enter the second number: " ) total_combination = float(first_number) + float(second_number) print ("your answer is" , total_combination) |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by Nobody: 10:15pm On Oct 16, 2017 |
Print is to display an output try input........ Read about numeric type like float, double,int...... |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 10:25pm On Oct 16, 2017 |
proxy20:Much thanks sir! Neatly summarised. I'd run it as soon as I power my pc. |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by Nobody: 10:26pm On Oct 16, 2017 |
LordeCalifornia: Use ideone.com to run on your phone |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by asalimpo(m): 11:00pm On Oct 16, 2017 |
@LordCarlifornia if you're using a pc - i.e desktop, then some of ur python code will not work. Python is designed for high end i.e modern systems, think laptops or modern to bleeding edge desktops. tl:dr- get a laptop. |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 2:25pm On Oct 17, 2017 |
proxy20:Alright. Thanks |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 2:27pm On Oct 17, 2017 |
asalimpo:Oops! My bad. I was thinking a laptop is equally a PC. I use a laptop not a desktop. Thanks. |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by Nascimento(m): 2:35pm On Oct 17, 2017 |
asalimpo: Sorry, what I don't understand. Please explain why it won't work on a desktop computer after installing the python setup? |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by crunchyDope(m): 5:18pm On Oct 17, 2017 |
LordeCalifornia: Looks like u just started learning python, u cld also learn without ur pc using "Qpython" and urm switch to python 3 k? |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 6:21pm On Oct 17, 2017 |
crunchyDope:Yeah I'm a newbie Qpython? I'd check that out. Thanks! |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by michaelwilli(m): 12:16pm On Oct 18, 2017 |
LordeCalifornia:For decimals, there's the double and float datatype, i don't know which python has, just check online. You'll need to cast it to either of the two types |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by michaelwilli(m): 12:17pm On Oct 18, 2017 |
asalimpo:Be saying rubbish dere |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 12:31pm On Oct 18, 2017 |
michaelwilli:Yeah. I've figured it out already. Thanks! |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by michaelwilli(m): 12:46pm On Oct 18, 2017 |
LordeCalifornia:Ya welcome |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by asalimpo(m): 10:12pm On Oct 18, 2017 |
LordeCalifornia:You're right. A lappy is a pc if it runs windows os. But typically, people usually call desktop 'pc'. So i thought u were talking desktop. pc = windows os. alternatives are mac (mac os), linux,unix. It can be confusing. |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by asalimpo(m): 10:12pm On Oct 18, 2017 |
michaelwilli:You dont seem to share my view, dyu use a desktop? |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by asalimpo(m): 10:27pm On Oct 18, 2017 |
Nascimento:The ram architecture of old systems can be an issue. Modern software is migrating to modern addressing. E.g if you try to learn android dev on a not too recent desktop, you will install the sdk successfully but the emulator will not work and genymotion or other emulators will not work. You'll bang ur head for days and not find the answer even on google!! - listening to your huncher - ur intuition, you may decide to try the set up on a more modern system and voila or is viola (the location the 'i' keeps confusing me) the problem is solved. There's a reason tech company programmers work on lappies!!. |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by LordeCalifornia: 10:38pm On Oct 18, 2017 |
asalimpo:Yeah. I even call my phone a PC |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by spoilerx: 10:33am On Oct 19, 2017 |
asalimpo: This is so not true !!!! |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by michaelwilli(m): 12:40pm On Oct 19, 2017 |
asalimpo: Just sharrap please, ya view makes absolutely no sense |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by asalimpo(m): 3:23pm On Oct 19, 2017 |
michaelwilli:Human beings? When they're being exposed they get mad. Do u use an oldie (old desktop for ya coding)! Tell us the specs of ur machine. |
Re: Python Masters, Kindly Help Me Rectify This Python Problem. by michaelwilli(m): 10:18pm On Oct 19, 2017 |
asalimpo:Weda high end or low end, basic python stuffs will run smoothly |
(1) (Reply)
Web Development Tutorials / . / How Do I Learn Web .net From C# Developer
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 43 |