#🔒 temperature unit converter

174 messages · Page 1 of 1 (latest)

safe atlas
#

code:

gray pilotBOT
#

@safe atlas

Python help channel opened

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.

safe atlas
#

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

bright prawn
#

Fix the indentions

safe atlas
#

what is an indention

#

can you give me an example

#

I dont know the titles

bright prawn
#
block
    indented_block
safe atlas
#

okay let me ask what is the indention in my code

bright prawn
#

Also use English language

safe atlas
#

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

upbeat anvil
#

Maybe I am off topic but if input is F then I think the calculation should be (F - 32) * 5 / 9

safe atlas
#
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
bright prawn
#

The indentions are realy off

#

You should fix it

safe atlas
#

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

safe atlas
#

and beside having an error

#

I said that I want to "add" a thing

safe atlas
#

"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"

bright prawn
#

That's it

#

Simple English language

torpid spruce
#

!indent

gray pilotBOT
#
Indentation

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

bright prawn
#

Yes

#

Its imposible to code on python without knowing this

safe atlas
#

yeah I know this

torpid spruce
#

@safe atlas indentation just means giving white space. If you don't indent properly or consistently, it will error out

safe atlas
#

but just dont understand by saying

#

block indent block sht

#

I thought its somethings name like ifs elses lol

#

Im saying Im very beginner

bright prawn
#

That's a term built by generation

#

Its just English word

safe atlas
#

yup

torpid spruce
bright prawn
#

Well based on your indention....

#

It's a total trash

#

._.

#

It will do nothing

#

And I have no idea how to indent it

safe atlas
#

I cant build

#

this isn't something fixable I know

torpid spruce
bright prawn
#

Syntax error

torpid spruce
#

Easiest way to fix anything is to tackle the errors as you go

safe atlas
#

yeah

#

I know these continue and breaks arent in loop

torpid spruce
safe atlas
#

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

torpid spruce
safe atlas
#

okay hlod on

bright prawn
#

This should be inside of any loop

#

It will give syntax error

safe atlas
#

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

bright prawn
#

I will suggest this flow

safe atlas
#

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

torpid spruce
#

ah

safe atlas
#

but it still asked me to type E or H

#

in H too

bright prawn
#

Create a loop while you want to loop
get the input
Process it
And ask if do again or stop

safe atlas
#

if I type H

#

it says that again

torpid spruce
#

Either you make another loop, wrapping the entire code, or make a function and put that inside the existing loop

safe atlas
#

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

torpid spruce
#

Its much preferred to start writing functions instead

safe atlas
#

like, what will I do with function?

torpid spruce
#

The point of a function is so that you can call it as many times as you like

bright prawn
#

like
f_to_c

#

Or c_to_f

#

Functions

safe atlas
#

can you give an example using this code?

torpid spruce
#

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

bright prawn
#

I don't think it will actually work if you outdent the loops

torpid spruce
#

It does

bright prawn
#

Wait

#

He want it to run only ones?

safe atlas
#

no

torpid spruce
#

OP wants it to continously run until 'H' is input

bright prawn
#

Se

safe atlas
#

yeah

bright prawn
#

You better rewrite it

torpid spruce
#
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

safe atlas
#

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

bright prawn
#
while True:
   input()
#

This will restart automatically

#

And you calling a function

torpid spruce
bright prawn
#

Better

torpid spruce
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

torpid spruce
#

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

safe atlas
#

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

torpid spruce
#

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.

safe atlas
#

I did them both

torpid spruce
#

And?

#

Did it work?

#

Did it reask?

bright prawn
#

Use this

#

Tanks me later

torpid spruce
#

bruh

safe atlas
#

can you send it to me like text...

bright prawn
#

I can't open discord on this Chromebook

#

...

safe atlas
#

okay

bright prawn
#

Outdated browser

safe atlas
#

Im copying it

bright prawn
#

When I was new I was wishing someone to do the same I did

torpid spruce
#

That's not in the spirit of this Discord server #code-of-conduct

bright prawn
#

Because

#

I will learn it better if I got a example

torpid spruce
#

I already gave like 2 examples

safe atlas
safe atlas
#

it reask

#

but I dont say it

#

Im saying

#

if I type

#

something else than

#

Y

#

I dont want code to just pass me

torpid spruce
#

you can add another if for that

bright prawn
#

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

torpid spruce
#

But... if OP really needs the user input as Y or E to literally continue, then yes

bright prawn
#

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

torpid spruce
#

It does work

bright prawn
#

Nice

torpid spruce
#

Just without the check for E or Y as what OP wants

#

But it works

safe atlas
#

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

gray pilotBOT
#
Python help channel closed

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.