When i run this code, the output is shown as "enter the km:miles is 4.8000 but i want it to show as "miles is 4.8000 ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

When i run this code, the output is shown as "enter the km:miles is 4.8000 but i want it to show as "miles is 4.8000 ?

how to do it? here is my code https://code.sololearn.com/c41n5BJd3uq3/?ref=app

7th Sep 2018, 9:07 AM
Shinsha
20 Respostas
+ 1
If it is the last line you didnt understand, that is a new feature in Python 3 called an f-string. All it does is it lets you format strings in an easier and faster way. Here's an example: Without f-strings: >>> "My name is %s. I'm a %s at %s" % (name, job, company) "My name is Shinsha. I'm a Software engineer at Google" or >>> "My name is {}. I'm a {} at {}".format(name, job, company) "My name is Shinsha. I'm a Software engineer at Google" Using an f-string: >>> f"My name is {name}. I'm a {job} at {company}" "My name is Shinsha. I'm a Software engineer at Google" ------------------ Here is a detailed explaination https://realpython.com/python-f-strings/ If you didn't understand anything else, let me know :)
7th Sep 2018, 9:59 AM
Just A Rather Ridiculously Long Username
+ 1
Add this before print(result) print(end="")
7th Sep 2018, 9:15 AM
Jonas Schrƶter
Jonas Schrƶter - avatar
+ 1
Use this: def convert(miles): km=1.6* miles print ("miles is ",end="") return km result1 = float(input("enter the km: ")) print (result1) result1 = convert(result1) print(result1) This will print the input value after thr colones and afterwards convert and print the number. If you don't want/need to print the input value, you can just add a \n to the end of input string to create a new line. "enter the km: \n"
7th Sep 2018, 9:29 AM
Matthias
Matthias - avatar
+ 1
This is a problem with the sololearn's code playground. Your code would work just fine on another IDE, for example https://trinket.io/python3/3bd822a984 But if you want to do it in code playground here's one way https://code.sololearn.com/cf2bwZ6U8pek/#py
7th Sep 2018, 9:38 AM
Just A Rather Ridiculously Long Username
+ 1
Matthias Thank you so much it worked. But is there anyway to show the output as only " miles is.. " without showing the kilometer input?
7th Sep 2018, 9:39 AM
Shinsha
+ 1
Only by avoiding a string in the input function. So just input() But maybe this again a problem just in Sololearn, as Just A Rather Ridiculously Long Username mentioned.
7th Sep 2018, 9:43 AM
Matthias
Matthias - avatar
+ 1
print(f"{x} bla") is formatted print. (that's why the f is at the beginning) Everything in {} is replaced by the variable value. another option would be print("{} bla".format(x)) or based on the other code: print('{} mi can be written as {} km'.format(inp, convert(inp))) You see, there are many ways in Python šŸ˜…
7th Sep 2018, 9:47 AM
Matthias
Matthias - avatar
+ 1
Oh.. I see. Iam a Newbie. still at the basics.so this is definitely a new concept. But Thank You So much. You helped me alot.
7th Sep 2018, 9:53 AM
Shinsha
+ 1
Not really. Only maintaing some sites part-time as a student job using HTML/PHP/SQL. Plus some online app developement in Python and for scientific computing mostly C/C++ and Python
7th Sep 2018, 10:04 AM
Matthias
Matthias - avatar
+ 1
Matthias Great.. I know C and C++ .but only the basics.. infact i only know the basics of programming.. so im upgrading myself. If you dont mind could you give me your Email id please? so that i can ask you some guidance in terms of learning programming. i want to study SQL AND PHP. But i dont have any friends who is learning/ learned programming language. Don't worry i wont budge you with my questions.. Just a friend to ask/ and clear my doubts. if you are not interested. its okay ill understand. Anyway Thank you so much for your help.
7th Sep 2018, 10:13 AM
Shinsha
+ 1
About 1-2 years ago, I was at the same place. Then I finally got the OOP-concept in C++ at since then programming is a lot easier šŸ˜… Sorry, I don't like to hand out my E-mail address in general. But you can tag me on SL whenever you like and if I have time I will be glad to help :) What I can tell you right away is to install xampp and try out as much as possible using php/sql. Especially creating forms. There are a lot of nice guides which can be found on the internet, Google was and is my best friend regarding programming questions šŸ˜…
7th Sep 2018, 10:22 AM
Matthias
Matthias - avatar
+ 1
Matthias Oh.. Its Okay Matthias. Thanks for telling me about the php/sql. I will do it. Yes You are right. Google is the best Friend. Not only for programming for eveything. yes ill follow you in SL. If i have doubts.. ill tag you. Thanks Matthias! It was really nice to Know you.
7th Sep 2018, 10:28 AM
Shinsha
0
Jonas Schrƶter hello, jonas i tried, still it shows the previous output?
7th Sep 2018, 9:20 AM
Shinsha
0
Just A Rather Ridiculously Long Username Thanks for letting me know. yes you are right, i tried and the output came exactly how i wanted. but with the Code playground code you wrote, i dont understand what you coded, could you please explain me .?
7th Sep 2018, 9:43 AM
Shinsha
0
Matthias Oh.. Thank You Matthias. ill keep that in my mind.
7th Sep 2018, 9:44 AM
Shinsha
0
Matthias Are you a web developer?
7th Sep 2018, 9:56 AM
Shinsha
0
Great.. I know C and C++ .but only the basics.. infact i only know the basics of programming.. so im upgrading myself. If you dont mind could you give me your Email id please? so that i can ask you some guidance in terms of learning programming. i want to study SQL AND PHP. But i dont have any friends who is learning/ learned programming language. Don't worry i wont budge you with my questions.. Just a friend to ask/ and clear my doubts. if you are not interested. its okay ill understand. Anyway Thank you so much for your help.
7th Sep 2018, 10:13 AM
Shinsha
0
Just A Rather Ridiculously Long Username Thank you so much sir/madam. coz i dont know your name. and this info is so much useful.. Now i understand. i havent learned string formatting yet. but the link you sent made it very clear . and also Thanks for calling me a "Software Developer at Google" in sha allah, one day i might get there and when i get there you would be the first person that i will tell.ā˜ŗ by the way i like your UserName. jokes apart, Thanks once again.
7th Sep 2018, 10:22 AM
Shinsha
0
No problem :) I'd be more than happy to help you out with any other doubts you come across too.
7th Sep 2018, 10:50 AM
Just A Rather Ridiculously Long Username
7th Sep 2018, 11:33 AM
Shinsha