Conversion


#1

i scripted a code for conversion of temperature fromm celsius to fahrenheit.

convert celsius to fahrenheit

celsius=int(input("Please enter the value for temperature:"))

conversion

fahrenheit=celsius+32
print (fahrenheit)
input ("Please press return to exit.")

Wanted to know how can i add a line in the print setion ie. while displaying the output,it should show as "The value for temperature in fahrenheit is:".Please enlighten.


#2

ideally, use .format():

print("The value for temperature in fahrenheit is: {:d}".format(fahrenheit))

see here, for more information about format


#3

its showing as syntax error


#4

Got it!!its running.Thank you.


#5

I am not saying .format() is the only way, but its the recommendent way

not sure how you got a syntax error, good that you solved it


#6

Can this format be used in the scripts where the output is an integer?


#7

what are the other ways?


#8

yes, of course, did you see the website i linked to:

https://pyformat.info/

it explains .format() in more detail, well then we have the old style (%d) which is explained there as well, then we have:

print("The value for temperature in fahrenheit is:", farenheit)

and string concenate:

print("The value for temperature in fahrenheit is: " + str(farenheit))

#9

Okay ,i will check it.


#10

Thank you :slight_smile:


#11

For taking in input containing only strings for it is: value=str(input("please enter a value"))
for numbers its: value=int(input("please enter a value")).
But may i know what is the syntax for taking in a mixture of alphabets and numbers?


#12

in programming, there isn't way one way to do something. So there isn't one way to solve what you are asking, there are several.

you could make separate prompts

integers can be represent as string. So depending on what you need it for, string integers might suit you

you could check for each character the user inputted if its a number (you can google this)


#13

Is this script technically correct?

#Login script
#Enter username and password
username=str(input("PLEASE ENTER USERNAME"))
password=int(input("PLEASE ENTER PASSWORD"))
#condition 
username=sudeep
if (username==sudeep) and (password==18051993):
    print ("Logged in")
else:
    print("Invalid login credentials")

#14

no, here:

username=sudeep

sudeep is a undefined variable, and it overwrites the user input, why would you do this?

here:

if (username==sudeep)

sudeep is a string, a string requires quotation marks or apostrophes


#15

Yes!!got it ..Thank you


#16

Facing an issue here.The program runs,but even when i input the correct username and password it shows "invalid login credentials".


#17

i ran your code here, everything works fine, i was able to login succesfully


#18

hi
what is ur problem that i can help u with


#19

Actually facing an issue with the login script.


#20

I tried runnng it.So the scrpt is okay?