0
String
How do we change several strings input into usable form
17 Antworten
+ 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.
+ 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.
+ 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.
+ 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.
+ 3
Missing closing parenthesis on the first int() call.
+ 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
+ 1
Ohhh thanks
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?
0
Brian Actually in that code there are two string input so how do I separate them and them operate them?
0
Use str() for converting integers into string
0
In one line only
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?
0
No anothar
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
0
It's again showing error
0
Brian you are right I was doing that only 😅but I am again stuck on it
0
int(b[0]*int(b[1])
if d>e:
print('Apartment A')
else:
print('Apartment B')
It's showing error in d>e: