+ 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
20 ответов
+ 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 :)
+ 1
Add this before print(result)
print(end="")
+ 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"
+ 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
+ 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?
+ 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.
+ 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 😅
+ 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.
+ 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
+ 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.
+ 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 😅
+ 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.
0
Jonas Schröter hello, jonas i tried, still it shows the previous output?
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 .?
0
Matthias Oh.. Thank You Matthias. ill keep that in my mind.
0
Matthias Are you a web developer?
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.
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.
0
No problem :)
I'd be more than happy to help you out with any other doubts you come across too.
0
Just A Rather Ridiculously Long Username Thank You. JARRLU☺