#🔒 temperature unit converter
174 messages · Page 1 of 1 (latest)
@safe atlas
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
while True:
unit = input("Fahrenheit mi yoksa Celsius mu yazacaksın (C/F): ").upper()
if unit in ['C', 'F']:
break
print("Lütfen geçerli bir birim yazınız")
while True:
try:
temp = float(input("Sıcaklık kaç derece: "))
break
except ValueError:
print("Lütfen geçerli bir sayı giriniz")
if unit == 'C':
temp = (9 * temp) / 5 + 32
print(f'Sıcaklık Fahrenheit birimiyle: {temp}°F')
elif unit == 'F':
temp = (temp + 32) * 5 / 9
print(f'Sıcaklık Celsius birimiyle: {temp}°C')
play_again = input("Tekrar kullanmak ister misin? (E/H): ")
while not (play_again == 'E' or play_again == 'H'):
print("Lütfen \"E\" yada \"H\" yazınız")
play_again = input("Tekrar kullanmak ister misin? (E/H): ")
if play_again == 'E':
continue
elif play_again == 'H':
break
thats the code
Fix the indentions
block
indented_block
okay let me ask what is the indention in my code
Also use English language
that wasn't a problem for the others my problem isn't even about it and I know code isn't right but let me ask my thing
I want this code to ask user if he wants to use the code again and if user says E the code restarts if user says H the code ends
I could translate it to english if its important for u
Maybe I am off topic but if input is F then I think the calculation should be (F - 32) * 5 / 9
while True:
unit = input("Fahrenheit or Celsius? (C/F): ").upper()
if unit in ['C', 'F']:
break
print("Please enter a valid unit")
while True:
try:
temp = float(input("What is the temperature: "))
break
except ValueError:
print("Please enter a valid number")
if unit == 'C':
temp = (9 * temp) / 5 + 32
print(f'Temperature in fahrenheit: {temp}°F')
elif unit == 'F':
temp = (temp + 32) * 5 / 9
print(Temperature in Celsius: {temp}°C')
play_again = input("Do you want to use again? (E/H): ")
while not (play_again == 'E' or play_again == 'H'):
print("Please type\"E\" or\"H\" ")
play_again = input("Do you want to use again? (E/H): ")
if play_again == 'E':
continue
elif play_again == 'H':
break
sorry but I dont even know what does that mean like I know english but I dont know what a present perfect tense I dont understand by names
and yeah thanks I missclicked or smth I think
and beside having an error
I said that I want to "add" a thing
block
Indented_block
"I want this code to ask user if he wants to use the code again and if user says E the code restarts if user says H the code ends"
!indent
Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.
Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.
Example
def foo():
bar = 'baz' # indented one level
if bar == 'baz':
print('ham') # indented two levels
return bar # indented one level
The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.
Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines
More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation
yeah I know this
@safe atlas indentation just means giving white space. If you don't indent properly or consistently, it will error out
but just dont understand by saying
block indent block sht
I thought its somethings name like ifs elses lol
Im saying Im very beginner
yup
Anyways, this latest code has a missing ' at
print(Temperature in Celsius: {temp}°C')
Well based on your indention....
It's a total trash
._.
It will do nothing
And I have no idea how to indent it
"my problem isn't even about it and I know code isn't right but let me ask my thing"
I know that code will do nothing and Im not saying how to fix it I need to build it from start
I cant build
this isn't something fixable I know
Whats the error that you're getting atm?
Syntax error
Easiest way to fix anything is to tackle the errors as you go
You're not OP. Help OP learn by reading and fixing the error but not spoonfeed. Thanks
but if I put them in loop
it doesnt work either
I need another loop I think
but Im so confused so asked in here
Saying "it doesnt work" is not helpful to anyone. Are you getting errors or is it that its not doing as what you're expecting it to?
okay hlod on
yeah
but
if I put it in this loop
while True:
unit = input("Fahrenheit mi yoksa Celsius mu yazacaksın (C/F): ").upper()
if unit in ['C', 'F']:
break
print("Lütfen geçerli bir birim yazınız")
while True:
try:
temp = float(input("Sıcaklık kaç derece: "))
break
except ValueError:
print("Lütfen geçerli bir sayı giriniz")
if unit == 'C':
temp = (9 * temp) / 5 + 32
print(f'Sıcaklık Fahrenheit birimiyle: {temp}°F')
elif unit == 'F':
temp = (temp - 32) * 5 / 9
print(f'Sıcaklık Celsius birimiyle: {temp}°C')
play_again = input("Tekrar kullanmak ister misin? (E/H): ")
while not (play_again == 'E' or play_again == 'H'):
print("Lütfen \"E\" yada \"H\" yazınız")
play_again = input("Tekrar kullanmak ister misin? (E/H): ")
if play_again == 'E':
continue
elif play_again == 'H':
break
like that
Im sending the output
I will suggest this flow
Seems to work
celcius or fahrenheit (C/F): c
whats the temperature: 3
temperature in fahrenheit: 37.4°F
do you want to use again (E/H): e
please write e or h
want to use again? (E/H):
I typed E
ah
Create a loop while you want to loop
get the input
Process it
And ask if do again or stop
Either you make another loop, wrapping the entire code, or make a function and put that inside the existing loop
I did something like that before and used another loop wrapping the code
but now Im doing it after I finished all the code
and I cant figure out where should I put the loop
Its much preferred to start writing functions instead
like, what will I do with function?
The point of a function is so that you can call it as many times as you like
can you give an example using this code?
Putting it in another loop is kinda ugly looking
# Your code
while True:
...
while True:
...
If you add a loop around your code, you have to indent everything
while True:
# Your code
while True:
...
while True:
...
The functions however, keeps it a cleaner and more organized
I don't think it will actually work if you outdent the loops
It does
no
OP wants it to continously run until 'H' is input
Se
yeah
You better rewrite it
def do_something():
print("Do something")
while True:
do_something()
user_input = input("Do you want to use again?\n")
if user_input == "E":
do_something()
elif user_input == "H":
break
Quick example
The do_something() is a function. You can basically move all of your celsious/fahrenheit temp converter into a function and then call it in side the loop
In my example, you can see its called twice in the loop. Once during the initial, another in the if block
So as long as the user inputs 'E', it will always call the do_something() function. If 'H', breaks the loop and ends the program
the problem is I dont know how can I make a function that makes all the code restart
I understand how do I use the function
but Im still at the same thing
Better
Tell me if this makes sense @safe atlas
yes that compleyely makes sense but now my problem is how do I make it reask if I type something like "Æ" to questions
whatever is in the loop, will keep doing what is in the loop
i.e. if the loop has "input()", it will keep re-asking that same question over and over again
Why don't you try it?
Here try this on a blank python script and run it:
count = 0
while True:
count +=1
print(f"{count=}")
user_input = input("Do you want to loop again? (E/H) ")
if user_input == "H":
break
Once you run it, you'll understand
Or use my example:
def add_numbers(a, b):
return a + b
while True:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print(add_numbers(num1, num2))
again = input("Do you want to use again? (Y/N): ")
if again == 'N':
break
the important part of the code totally makes sense
I understand these both
but it start being problem
when I got into details
like
I want this code to reask if I dont put Y
or if I type "{" for number
We need the details of the problem so we can help. At the moment, I'm not hearing or seeing what the problem is. It looks like you havn't tried running either of my examples.
I did them both
bruh
can you send it to me like text...
okay
Outdated browser
Im copying it
It's easier to just give him the answer than to let him do it
When I was new I was wishing someone to do the same I did
That's not in the spirit of this Discord server #code-of-conduct
I already gave like 2 examples
I try to explain this for 150 messages...
you got me wrong
it reask
but I dont say it
Im saying
if I type
something else than
Y
I dont want code to just pass me
you can add another if for that
So you talking a course?
I don't include if for Y because what it will do is just continue
And it's same as don't placing it
Exempt there's some code you don't wanna get executed behind it
But on the code I sent
It's fine
But... if OP really needs the user input as Y or E to literally continue, then yes
You better take a note
I don't know if my code will work
I can't test it on my Chromebook
Paste it here
It does work
Nice
brooo I talked with like twenty more people and they just did it and I compared my wrong code and their correct code and find the error and just in twenty messages thats 160 messages and I dont know why do you guys have your own weird rules
thats my second project okay I dont understand your complex codes like
fjefeko = x
eıjfe = e
x e +*3%^%^exxe e ex yy xy
or some basic examples I did understand
sorry but you guys didnt understand my questions for 160 messages
and what I wanted is
the code to say me "hey you should type Y or N" if I type something else thats so basic how did you doesnt get it and give me examples like
if 3 > 2
print("3 is greater than two yay")
that shouldn't be took that long I will ask these another time
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.