0

String

How do we change several strings input into usable form

5th May 2024, 3:38 PM
Raine04
Raine04 - avatar
17 Answers
+ 5
Raine04 are the input strings on one line, or are they on separate lines? Again, I request that you would please show an example of the specific inputs and outputs you desire. The details are important and it would clear up many questions.
6th May 2024, 5:56 PM
Brian
Brian - avatar
+ 5
Raine04 it is unclear what you mean by "usable form". Please give an example. Also if you have some code that you are working on to implement the idea, then show a link to your code. That would help to clarify your intent.
5th May 2024, 6:28 PM
Brian
Brian - avatar
+ 5
Raine04 , to get numerical values from an input in python (inputs in python are always a string by default), we can convert them to integer datatype or to float datatype. int_num = int(input()) or respectively for float: float_num = float(input()) after the conversion we can use the values for calculations.
6th May 2024, 3:26 PM
Lothar
Lothar - avatar
+ 3
Raine04 I recognize that you are solving the Balconies Code Coach task. The task gives inputs as strings like this: '5,5' '2,10' You need to split the strings on the comma delimiter and, when converting them to integer, include more than one digit. Your code is converting only single characters to int. Use split(",") to break up each input line by comma into a list of strings. Then work out how to convert each list into integers. If you have intermediate Python skill, then you might try the map() function to do that. But there are other ways that just use a little more code.
7th May 2024, 3:10 PM
Brian
Brian - avatar
+ 3
Missing closing parenthesis on the first int() call.
7th May 2024, 3:46 PM
Brian
Brian - avatar
+ 1
As Brian said, it is unclear what is an usable form of strings, but if you want to use numbers from strings, there are the int() and float() commands, as in this code: https://sololearn.com/compiler-playground/c9hRia4G5XCr/?ref=app
5th May 2024, 7:03 PM
underlineyou
+ 1
Ohhh thanks
7th May 2024, 4:55 PM
Raine04
Raine04 - avatar
0
Thank you guys for your attention Actually I was writing a code in which we have to take input of two number as strings and then multiply them separately how do we do that?
6th May 2024, 9:05 AM
Raine04
Raine04 - avatar
0
Brian Actually in that code there are two string input so how do I separate them and them operate them?
6th May 2024, 4:48 PM
Raine04
Raine04 - avatar
0
Use str() for converting integers into string
7th May 2024, 7:36 AM
Vaishnavi Kachhi
Vaishnavi Kachhi - avatar
0
In one line only
7th May 2024, 12:16 PM
Raine04
Raine04 - avatar
0
a=input() b=input() aa=int(a[0])* int(a[1]) ab=int(a[0])* int(a[1]) if aa>ab: print('Apartment A') else: print('Apartment B') Guys in this code it's showing error can you tell whats wrong?
7th May 2024, 12:25 PM
Raine04
Raine04 - avatar
0
No anothar
7th May 2024, 12:54 PM
Rahul Vaghona
Rahul Vaghona - avatar
0
a=input().split(',') b=input().split(',') aa=int(a[0])*int(a[1]) ab=int(b[0]*int(b[1]) if aa>ab: print('Apartment A') else: print('Apartment B') Try this
7th May 2024, 3:23 PM
ROOPASHREE S
ROOPASHREE S - avatar
0
It's again showing error
7th May 2024, 3:32 PM
Raine04
Raine04 - avatar
0
Brian you are right I was doing that only 😅but I am again stuck on it
7th May 2024, 3:33 PM
Raine04
Raine04 - avatar
0
int(b[0]*int(b[1]) if d>e: print('Apartment A') else: print('Apartment B') It's showing error in d>e:
7th May 2024, 3:35 PM
Raine04
Raine04 - avatar