SCMA241 Lab : Python Basic

In [1]:
# exercise 1 : print function
print("Krikamol Muandet")
print("Mahidol University")
print("096923878X")
print("Mathematics")

Krikamol Muandet
Mahidol University
096923878X
Mathematics

In [2]:
# exercise 2 : input function and basic calculation
sales = int(input("Total sales? ")) # get the total sales
profit = 0.23*sales # calculate the profit
print("The profit is ",profit)

Total sales? 110
The profit is  25.3

In [11]:
# exercise 3
square_feet = float(input("Land size (in sq. feet)? "))
acre = square_feet/43560 # convert to acre
print(square_feet," square feet is ",acre," acres.")

Land size (in sq. feet)? 5867444
5867444.0  square feet is  134.6979797979798  acres.

In [13]:
# exercise 4
price1 = int(input("Product 1: "))
price2 = int(input("Product 2: "))
price3 = int(input("Product 3: "))
price4 = int(input("Product 4: "))
price5 = int(input("Product 5: "))

total_price = price1+price2+price3+price4+price5
tax = 0.07*total_price

total = total_price + tax
print("Total price : ",total_price)
print("Tax : ",tax)
print("Total : ",total)

Product 1: 55
Product 2: 120
Product 3: 75
Product 4: 88
Product 5: 159
Total price :  497
Tax :  34.790000000000006
Total :  531.79

In [15]:
# celsius to fahrenheit
celsius = int(input("Celsius? "))
fahrenheit = (9/5)*celsius + 32
print("Farenheit : ",fahrenheit)

Celsius? 120
Farenheit :  248.0

In [18]:
# male and female percentages
num_male = int(input("Number of male students? "))
num_female = int(input("Number of female students? "))

total = num_male + num_female
male_pc = 100*(num_male/total)
female_pc = 100*(num_female/total)

print("Male : ", male_pc, " Female : ", female_pc)

Number of male students? 22
Number of female students? 14
Male :  61.111111111111114  Female :  38.88888888888889

In [ ]: