How do you use str and int in the same input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do you use str and int in the same input

like the question says i want to be able to have a single input that takes strings as well as taking any integers i input and use that int in part of the code is that possible?the only reason i only want one input for both is because i want to use the code here on the coding playground and ill only need the int input some of the time

4th Aug 2017, 9:36 AM
Daniel Robertson
Daniel Robertson - avatar
1 Answer
0
Use one big input (l=input()) and apply one of the 2 following solutions : A) use a separator character like space and do l.split(' '), use the result in a loop like that : for i in l: try: x=int(i) except: #string part else: #int part B) consider that any group of numbers are integers For that, you'll have to separate the list manually by delimiting zones of the string with only number (I can make a code as an example if you need)
4th Aug 2017, 9:45 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar