0% found this document useful (0 votes)
9 views2 pages

Replit Exercise

Uploaded by

Fitri Safira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Replit Exercise

Uploaded by

Fitri Safira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

# Print

print("Hello World!")
print("What is your name?")

# input () will get user input in console


input("What is your name?")

# save the input as a variable


# Then print() will print the word "Hello" and the variable
name = (input("What is your name?"))
print("Hello " + name)

# Coding exercise - ice cream name generator


# you are a food scientist and you are trying to come up with a name for your
new ice cream flavor. Your ice cream name will be: your favorite color and
the fruit that you hate.
# For example, if your favorite color is blue and the fruit that you hate is
strawberry, your ice cream name will be Blue Strawberry

color = (input("What is your favorite color?"))


fruit = (input("What fruit you hate the most?"))
print("Your new ice cream flavor is " + color + " " + fruit)

#Data Types
#"String" - alwasy with double quotes

print("Hello")

#Integer - whole numbers, without " " python will treat numbers as numbers
and not string
print(123 + 123)
print(123_456_789)

#Float - numbers with decimal places, floating point number


# 3.14159

#Mathematical Operations in Python


# 3 + 5
# 7 - 4
# 3 * 2
# 6 / 3
# 2 ** 3
# PEMDASLR - order of priority
print(3*(3+3)/3-3)
print(3**2)

# Rounding
print(round(8/3, 2)) #round to 2 decimal places

#Change data type from integer to float


a = float(123)
print(type(a))
# Change data type from string to float
print(70 + float("100.5"))

#f-String - mix strings and different data types


age = 30 #integer
height = 1.8 #float

#Use f-String to convert all data types to string


f"your age is {age} years old, your height is {height} meters."
print(f"your age is {age} years old, your height is {height} meters.")

# Coding exercise - discount calculator


#If the total bill was $150.00 with 15% discount, the final amount you have
to pay is ($150*(1-0.15)) = $120
#Round the result to 2 decimal places.
print("Welcome to the discount calculator!")
bill = float(input("What was the total bill? $"))
discount = int(input("How much is the discount in percentage? "))

discount_percentage = discount / 100


discount_amount = bill * discount_percentage
total_payment = bill - discount_amount
final_amount = round(total_payment, 2)

print(f"The final amount to pay after a {discount}% discount is:


${final_amount}")

You might also like