Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,217 members, 7,818,752 topics. Date: Monday, 06 May 2024 at 12:19 AM

Python Experts - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Python Experts (1152 Views)

Python �� Beginners And Experts / [Code Review Help] Laravel Experts Please HELP! / Unity 3d /unreal Engine Experts? (2) (3) (4)

(1) (Reply) (Go Down)

Python Experts by Trizyd(m): 1:31pm On Aug 09, 2019
I'm currently learning Python programming language, and currently working on Control Flows.. I have this issues, if I can't figure out a problem, I just get stuck there. I'm working on an exercise to give me the data type of an input.

Here's a code I did that worked

data = 11
type(data)
if type(data) == str:
print( "It's a string" )
elif type(data) == int:
print("It's an integer" )

print(type(typed))


The output is
Its a number


Now my problem, I want to use a raw input, it prompts the user to type in something, it then determines if it's a string or integer

I used raw_input=("Enter something : " )


But my output no matter what I input is always converted to string

And ideas for me?
Re: Python Experts by Nobody: 3:27pm On Aug 09, 2019
p= input(" please input data:"wink
if not p.isdigit(): print (" this is a integer data type" , p) else: print(" this is string data type", p)
NOTE: p is the variable name isdigit is a string method
Remember, you can iterate it in a loop like while True: p= input(" please input data:"wink
if not p.isdigit(): print (" this is a integer data type" , p) else: print(" this is string data type", p) enjoy...
Re: Python Experts by Nobody: 3:31pm On Aug 09, 2019
don't use raw_input() it is outdated for python 3x input() is used
Re: Python Experts by Trizyd(m): 3:43pm On Aug 09, 2019
pavicky:
don't use raw_input() it is outdated for python 3x input() is used


Yeah, thanks I just found out too..
Re: Python Experts by Trizyd(m): 3:45pm On Aug 09, 2019
pavicky:
p= input(" please input data:"wink

if not p.isdigit():
print (" this is a integer data type" , p)
else:
print(" this is string data type", p)

NOTE: p is the variable name
isdigit is a string method

Remember, you can iterate it in a loop like
while True:
p= input(" please input data:"wink

if not p.isdigit():
print (" this is a integer data type" , p)
else:
print(" this is string data type", p)
enjoy...

Thanks, it works... Except for the if not p.isdigoit should have a print statement of string type will the else that's the integer.. buh thanks.. Python is getting more interesting

2 Likes

Re: Python Experts by Daejoyoung: 3:46pm On Aug 09, 2019
smiley
Re: Python Experts by micodon(m): 5:43pm On Aug 09, 2019
Raw_input and input always returns a string
Re: Python Experts by romeo1000(m): 12:07pm On Sep 25, 2022
Hello . Do forgive my going offpoint but I have a question concerning mellin thread and Amira(the moon name)
Re: Python Experts by quickhubservice: 9:33pm On Sep 25, 2022
methods would help

(1) (Reply)

What Are Your Thoughts On Building A Utility Bill Payment Web And Mobile App? / A Web Developer Needed (good Pay) / How To Create A Winning Booking App & Website?

(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. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.