Python Forum
Post IF Statement Input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post IF Statement Input
#1
So i've been tasked with:

Write a Python program that does the following:
1. Ask the use if he/she wants to convert from Fahrenheit to Celsius or Celsius to
Fahrenheit.

2. If the user wants to convert from Fahrenheit to Celsius
a. Ask the user to enter the Fahrenheit temperature
b. Calculate the Celsius equivalent using formula b above
c. Print the Celsius equivalent with 3 places to the right of the decimal

3. If the user wants to convert from Celsius to Fahrenheit
a. Ask the user to enter the Celsius temperature
b. Calculate the Fahrenheit equivalent using formula a above
c. Print the Fahrenheit equivalent with 3 places to the right of the decimal

MY CODE IS:

print("Option 1: Convert Fahrenheit to Celsius")
print("Option 2: Convert Celsius to Fahrenheit")
choice = str(input("Which do you want to do?    Option "))
if choice == 1:
    fahrenheit = int(input("Enter the temp in Fahrenheit: "))
    print("The Celsius equivalent is: ", (fahrenheit - 32)*(5/9))
if choice == 2:
    celsius = int(input("Enter the temp in celsius: "))
    print("The Farhenheit equivalent is: ", (celsius*9/5)+32)
OUTPUT:
Output:
Option 1: Convert Fahrenheit to Celsius Option 2: Convert Celsius to Fahrenheit Which do you want to do? Option 1 PS C:\Users\AdamC\Desktop\VS Code>
my code isn't populating the input string after the if statements. I'm completely new to coding and this is my first coding class, and i'm not finding an answer. Any help is greatly appreciated.
Yoriz write Jun-04-2021, 09:53 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Post IF Statement Input - by OrphanedSoul - Jun-04-2021, 01:49 AM
RE: Post IF Statement Input - by OrphanedSoul - Jun-04-2021, 02:05 AM
RE: Post IF Statement Input - by deanhystad - Jun-04-2021, 05:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  if/else statement only outputs else statement regardless of input KameronG 2 2,556 Feb-08-2019, 08:04 AM
Last Post: KameronG
  Help Formatting Print Statement (input from 3 lists) X 2 Hebruiser 11 6,197 Dec-06-2017, 04:47 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020