Python Code Training for Week 1

Python Print Statement Exercise

Write the code that prints the following sentence:

Example:1

print("Welcome to the World of Machines and Robots")

Example:2

nameStudent = "Jack"
gradeStudent = "A"
print("Name :"+nameStudent)
print("Grade :"+gradeStudent)

Example:3

num1 = 1190
num2 = 3
num3 = num1 + num2
num4 = num1 - num2
num5 = num1 * num2
num6 = num1/num2
print("Addition of two numbers = ",num3)
print("Difference of two numbers = ",num4)
print("Product of two numbers = ",num5)
print("Quotient of two numbers = ",num6)

Example:4

# how to concatenate two Strings
nameUser = "Jasmine"
ticketNumber = "190005"
airlineName = "SpaceSky"
# this is how we get the strings printed on a single line
print("Passenger Name: "+nameUser+" AirLine Name: "+airlineName+" Ticket Number: "+ticketNumber)
print("*"*77)

Example:5

# I will get the user name and user score and user telephone and get it displayed as a output
useName = input("Please Enter student Name : ")
useScore = input("Please Enter student Score : ")
useTelephone = input("Please Enter student Contact : ")
print("*"*70)
print("Name : "+useName)
print("Grade : "+useScore)
print("Contact Phone : "+useTelephone)
print()
print("*"*70)

Example:6

# how do you get numeric quantity and perform addition and display it
# a user is making a Bank deposit , and the bank is paying 2% interest,
# the total amount should reflect the interest + the amount deposited by the user
userDeposit = int(input("Please Enter the Amount you wish to Deposit: "))
interestCalculator = 0.02*userDeposit
totalAmount = userDeposit + interestCalculator
print("*"*50)
print("Available Depost with Interest : ",totalAmount)
print("*"*50)

Example:7

# decimal quantities in python: Temperature converstion, Farenheit to Celsius
tempFarenheit = float(input("Please Enter the Temperature in Farenheit :"))
celsiusConversion = (tempFarenheit-32.0)*5/9
print("*"*75)
print("The Temperature Given in Farenheit = ",tempFarenheit)
print("The Temperature in Celsius = ",celsiusConversion)
print("*"*75)

Example:8

# we will learn how to get the quotient from the division
userInput = int(input("Please Enter the Number :"))
divisorInput = int(input("Please Enter the Divisor :"))
quotientValue = int(userInput/divisorInput)
print("The Quotient = ",quotientValue) print("The number of times ",divisorInput," divides ",userInput," is = ",quotientValue,"times")

Example:9

# We will get the Remainder when Division occurs : Modular Division
userInput = float(input("Please Enter the number :"))
divisorInput = float(input("Please Enter the divisor :"))
computationValue = userInput % divisorInput
print("The Remainder upon Division = ",computationValue)

Example:10

# this is going to find us the Exponents of a base userInput = int(input("Please Enter the Base :")) userIndex = int(input("Please Enter the Index | Exponent value :")) valueCalculated = (userInput)**(userIndex) print("The Value when ",userInput," is raised to the power of ",userIndex," = ",valueCalculated)

Example:11

# this is used to generate a Random number which is an Integer import random
userInput1 = int(input("Please give the initial boundary : "))
userInput2 = int(input("Please give the final boundary : "))
randNumber = random.randint(userInput1,userInput2)
print("The Random Integer Generated is = ",randNumber)

Example:12

# we will how to generate Random numbers between 0 and 1 import random
randomNumber = random.random()
print("The Generated Random Number = ",randomNumber)