How to change the string Into a number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to change the string Into a number

https://code.sololearn.com/c2unzyuzfTy0/?ref=app

10th Mar 2023, 12:57 AM
Ammar Alshawafi
Ammar Alshawafi - avatar
6 Answers
+ 9
Use int function string = '123' print(int(string)) read the description again you have to take inputs and split it to convert in list then you have to compare each value of the list with given conditions like water cost is 4 so for x in list: if x == 'water': cost = cost + 4 elif x == 'pizza' cost = cost + 6 after getting final cost do calculation as per given conditions to get final value.
10th Mar 2023, 2:04 AM
A͢J
A͢J - avatar
+ 4
Example like this:- n = int(input("enter number")) So, if we input anything from the user by default it takes input into string so if you want to convert into integers data type then you can put int before the input.
10th Mar 2023, 6:57 AM
Sakshi
Sakshi - avatar
+ 4
friend.... thats what chatGPT is good for. Give it a try! It will be your companion in future.
10th Mar 2023, 8:23 AM
Oma Falk
Oma Falk - avatar
+ 3
Use the int function! For example: num = “2023” print(int(num)) There is a lesson about converting strings to ints!
10th Mar 2023, 9:44 AM
UcloudBot2023
UcloudBot2023 - avatar
+ 2
Python can know numbers without any thing but to make sure you can add int () to you code
11th Mar 2023, 11:02 PM
Youssif Abbas
Youssif Abbas - avatar
0
Turn the ‘123’ into a “123”
10th Mar 2023, 4:46 PM
Jason Nguyen
Jason Nguyen - avatar