# -*- coding: utf-8 -*-
"""ln 5 Book Back Exercises_Getting Started with Python.ipynb
Automatically generated by Colaboratory.
Original file is located at
    https://colab.research.google.com/drive/1FTzabqecucB77IjOrgtXdK2LdPpHASus
#About this notebook
Notebook made by: Dhananjay M.R
Subject: Computer Science - Grade 11 CBSE
Language: - Python
Topic: Book Back Exercise Questions of the lesson - Getting Started with Python
Execution mode: Script Mode
Note: Theory based questions are not available in this notebook.

Note: This is a compilation of the entire book. 
If you run this program directly, you may encouter with error.
Therefore it is recommended to cut the program (modify) and run it part by part

Refering the original file at Colaboratory is recommended for better understanding of the codes
Original file is located at
    https://colab.research.google.com/drive/1FTzabqecucB77IjOrgtXdK2LdPpHASus

# Qn No.2 Write the corresponding Python assignment statements: 
"""

# Qn. Assign 10 to variable length and 20 to variable breadth.
# Solution for A
length = 10     #Assigns the value 10 to the variable length
breadth = 20    #Assings the value 20 to the variable breadth

length = 10 
breadth = 20
# The above values are from the part a of the qn, required for the b part

# Qn. Assign the average of values of variables length and breadth to a variable sum.
# Solution for B

sum = (length + breadth)/2    #Average
print(sum)    #Optional statement (used here to verify the answer)

# Qn. Assign a list containing strings ‘Paper’, ‘Gel Pen’, and ‘Eraser’ to a variable stationery.
# Solution for C
stationery = ['Paper', 'Gel Pen', 'Eraser']   #Assigns the strings in a list
print(stationery)    #Optional statement (used here to verify the answer)

# Qn. Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and last.
# Solution for D
first = 'Mohandas'
middle = 'Karamchand'
last = 'Gandhi'

first = 'Mohandas'
middle = 'Karamchand'
last = 'Gandhi'
# The above values are from the a part D of the qn, required for the E part

# Qn. Assign the concatenated value of string variables first, middle and last 
#to variable fullname. Make sure to incorporate blank spaces appropriately 
#between different parts of names.

# Solution
fullname = first + ' ' + middle + ' ' + last  #Concating the values
print(fullname)    #Optional statement (used here to verify the answer)

"""#Qn No.4 Add a pair of parentheses to each expression so that it evaluates to True. 

a)0 == 1 == 2 

b)2 + 3 == 4 + 5 == 7 

c)1 < -1 == 3 > 4   
"""

# Solution for part A
(0 == (1 == 2))

# Solution for part B
(2 + (3 == 4) + 5) == 7

# Solution for part C
(1 < -1) == (3 > 4)

"""#Qn No.5 Write the output of the following: """

#Part A.
num1 = 4 
num2 = num1 + 1 
num1 = 2 
print('Output for the part A of the question is:')
print(num1, num2) 

print('')

# Part B.
num1, num2 = 2, 6 
num1, num2 = num2, num1 + 2 
print('Output for the part B of the question is:')
print(num1, num2)

print('')

# Part C.
num1, num2 = 2, 3 
num3, num2 = num1, num3 + 1 
print(num1, num2, num3)
#Note: Part c ends up with a error :)

"""#Qn No 7. Write the output for the following when:
num1 = 4

num2 = 3

num3 = 2
"""

num1 = 4
num2 = 3
num3 = 2
# The above are some global variables (here only)

# Part A
num1 += num2 + num3
print('Output for Part A: ')  #Optional Statement
print(num1)
# End of part A

print('')

# Part B
num1 = num1 ** (num2 + num3)
print('Output for Part B: ')  #Optional Statement
print(num1)
# End of part B

print('')

num1 = 4 #Redeclaring value of num1 as we have changed it in last operation

# Part C
num1 **= num2 + num3
print('Output for Part C: ')  #Optional Statement
print(num1)
# End of part C

print('')

# Part D
num1 = '5' + '5'
print('Output for Part D: ')  #Optional Statement
print(num1)
# End of part D

print('')

# Part E
print('Output for Part E: ')  #Optional Statement
print(4.00/(2.0 + 2.0))
# End of part E

print('')

# Part F
num1 = 2 + 9 * ((3*12)-8)/10
print('Output for Part F: ')  #Optional Statement
print(num1)
# End of part F

print('')

# Part G
num1 = 24//4//2
print('Output for Part G: ')  #Optional Statement
print(num1)
# End of part G

print('')

# Part H
num1 = float(10)
print('Output for Part H: ')  #Optional Statement
print(num1)
# End of part H

print('')

# Part i - It ends up with an error, hence will be shown in the end
print('Part i ends up with an error, hence will be shown in the end')

print('')

# Part J
print('Output for Part J: ')  #Optional Statement
print('BYE' == 'Bye')
# End of part J

print('')

# Part K
print('Output for Part K: ')  #Optional Statement
print(10 != 9 and 20 >= 20)
# End of part K

print('')

# Part L
print('Output for Part L: ')  #Optional Statement
print(10 + 6 * 2 **2 != 9 //4 - 3 and 29 >= 29/9)
# End of part L

print('')

# Part M
print('Output for Part M: ')  #Optional Statement
print(5 % 10 + 10 < 50 and 29 <= 29)
# End of part M

print('')

# Part N
print('Output for Part N: ')  #Optional Statement
print((0 < 6) or (not(10 == 6)) and (10 < 0))
# End of part N

print('')

# Part I
num1 = int('3.14')
print(num1)

"""#Qn No.10 Write a python program to:
Convert temperature in degree Celsius to degree Fahrenheit. If water boils at 100 degree C and freezes as 0 degree C, use the program to find out what is the boiling point and freezing point of water on the Fahrenheit scale.   

(Hint: T(°F) = T(°C) × 9/5 + 32)

Note: Here in the question the input value is not required as we just have to convert the boiling/melting point from celcius to fahrenheit & the boiling/melting point in celcius is already given in the question.
"""

# Source Code: 

bp = 100    #Boiling point in Celcius
fp = 0      #Freezing point in Celcius

bp_fahr = bp * (9/5) + 32   #Boiling point in Fahrenheit
fp_fahr = fp * (9/5) + 32   #Freezing point in Fahrenheit

print('Freezing point of water in Celcius is: ', fp)
print('Boiling point of water in Celcius is: ', bp)

print('')

print('Boiling point of water in Fahrenheit is: ', fp_fahr)
print('Boiling point of water in Fahrenheit is: ', bp_fahr)

"""#Qn No.11 Write a python program to
Write a Python program to calculate the amount payable if money has been lent on simple interest. Principal or money lent = P, Rate of interest = R% per annum and Time = T years. 

Then Simple Interest (SI) = (P x R x T)/ 100. 

Amount payable = Principal + SI.   

P, R and T are given as input to the program.
"""

P = float(input("Enter the amount: "))
T = float(input("Enter the number of years: "))
R = float(input("Enter the rate of interest: "))

SI = (P * T * R)/100
Amount = P + SI

print('')   # Optional Statement
print("The simple interset is: ",SI)
print('The payable amount is: ', Amount)

"""#Qn No.12 Write a python program to: 
Write a program to calculate in how many days a work will be completed by three persons A, B and C together. A, B, C take x days, y days and z days respectively to do the job alone. The formula to calculate the number of days if they work together is xyz/(xy + yz + xz) days where x, y, and z are given as input to the program.
"""

x = int(input('Enter the number of days in which person A will take to complete the work: '))
y = int(input('Enter the number of days in which person B will take to complete the work: '))
z = int(input('Enter the number of days in which person C will take to complete the work: '))
together = x * y * z / (x*y + y*z + x*z)
print('')
print('If the three people work together, the work can be completed in: ', together, ' days')

"""#Qn No.13 Write a python program to:
Enter two integers and perform   all arithmetic operations on them.
"""

a = float(input('Enter the first number: '))
b = float(input('Enter the second number: '))

sum = a + b
difference = a - b
product = a * b
quotient = a/b

print('')

print('The sum of a', a, 'and', b, 'is', sum)
print('The difference of a', a, 'and', b, 'is', difference)
print('The product of a', a, 'and', b, 'is', product)
print('The Quotient of a', a, 'and', b, 'is', quotient)

"""#Qn No.14 Write a python program to: 
Swap two numbers using a third variable.
"""

x = input('Enter a value for x: ')
y = input('Enter a value for y: ')

print('')

print('Values before swapping:')
print('The value of x is:', x)
print('The value of x is:', y)

print('')

x,y = y,x

print('Values after swapping:')
print('The value of x is:', x)
print('The value of x is:', y)

"""#Qn No.15 Write a python program to: 
Swap two numbers without  using a third variable.
"""

x = input('Enter a value for x: ')
y = input('Enter a value for y: ')

print('')

print('Values before swapping:')
print('The value of x is:', x)
print('The value of x is:', y)

print('')

k = x
x = y
y = k

print('Values after swapping:')
print('The value of x is:', x)
print('The value of x is:', y)

"""#Qn No.16 Write a python program to:
Repeat the string ‘‘GOOD MORNING” n times. Here ‘n’ is an integer  entered by the user.
"""

n = int(input('Enter the number of times you would like to repeat the message ‘‘GOOD MORNING”: '))
print('')
print('Good Morning ' * n)

"""#Qn No.17 Write a python program to:
Find average of three numbers.
"""

a = float(input('Enter first number: '))
b = float(input('Enter second number: '))
c = float(input('Enter third number: '))

print('')

avg = (a + b + c)/3
print('The average of the 3 values is:', avg)

"""#Qn No.18 Write a python program to:
Find the volume of spheres with radius 7cm, 12cm, 16cm, respectively.

The volume of a sphere with radius r is 4/3πr3
"""

rad1 = 7
rad2 = 12
rad3 = 16
# The above are the radius of the speheres given in the question

pi = 22/7     #Value of pi

vol1 = 4/3 * pi * (rad1**3)
vol2 = 4/3 * pi * (rad2**3)
vol3 = 4/3 * pi * (rad3**3)

print('The volume of the spehere with radius', rad1, 'is:', vol1)
print('The volume of the spehere with radius', rad2, 'is:', vol2)
print('The volume of the spehere with radius', rad3, 'is:', vol3)

"""#Qn No.19 Write a python program that
Asks the user to enter their name and age. Print a  message addressed to the user that tells the user the year in which they will turn 100 years old.
"""

name = str(input('Enter your name: '))
crtage = int(input('Enter your current age: '))
centage = 100 - crtage
print('')
print('Hello', name, 'Your current age is', crtage, 'and in', centage, 'years,1 you will turn 100 years old')

"""#Qn No.20 Write a program that
Accepts the mass of an object and determines its energy.

The formula E = mc2 states that the equivalent energy (E) can be calculated as the  mass (m) multiplied by the speed of light (c = about 3×108 m/s) squared. Write a program.
"""

m = float(input("Enter the mass in g: "))
c = 3 * 10 ** 8
e = (m/1000) * c ** 2
print("The energy of an object with mass",m," grams ",e,"Joule.")
