Hi, currently i am studying python language as a one of the subjects in University. From my point of view it not difficult to learn. Here , i am going to post regards python language study materials such as ebook that i am using to study python. in additon , i am going to post my lecture notes , tutorials with answer and also i am going to post the answers for exercises in each chapter that ebook have.
if you are interested to study python, i recommanded this book , you can download this python ebook here :-python-ebook
i hope it will bring benefits to you.
Now, i am going to start with chapter -2 (input , processing and output)
Here, i have attached my Lecture notes ppt slides for chapter 2.some of the slides contains informations from chapter 1 if you are interested you can read
In this chapter you will learn
• Displaying output with print function
• Variables and assignment statement
• Variable reassignment
• Reading input from the keyboard
• Performing calculations
• More about output with print function
• Formatting numerical output
• Formatting numerical output
programming exercises
You can find these exercise questions at the end of the chapter 2 in the book that i attached above, here i have written answers for each questions in exercises. So, you can check with your answers
1. Personal Information
Write a program that displays the following information:
• Your name
• Your address, with city, state, and ZIP
• Your telephone number
• Your college major
answer :-
name = input("Enter your name : ")
city = input("Enter your city name : ")
state = input("Enter the state : ")
zipCode = input("Enter the ZIP code : ")
tpNumber = input("Enter the Telephone number : ")
collegeMajor = input("Enter the college major : ")
print("your name : ",name)
print("your address with city,state,zip : "+city+","+state+","+zipCode)
print("your telephone number : ",tpNumber)
print("your college major : ",collegeMajor)
2.Sales Prediction
A company has determined that its annual profit is typically 23 percent of total sales. Write a program that asks the user to enter the projected amount of total sales, and then displays the profit that will be made from that amount.
A company has determined that its annual profit is typically 23 percent of total sales. Write a program that asks the user to enter the projected amount of total sales, and then displays the profit that will be made from that amount.
Hint: use the value 0.23 to represent 23 percent.
answer :-
#Get the total sales
projectedTotalSale = float(input("Enter the projected amount of total sales : "))
#calculate the total profit
profit = projectedTotalSale * .23
#display the profit
print("profit will be :",format(profit , ',.2f'))
3.Land Calculation
One acre of land is equivalent to 43,560 square feet. Write a program that asks the user to enter the total square feet in a tract of land and calculates the number of acres in the tract.
Hint: divide the amount entered by 43,560 to get the number of acres.
answer :-
#Get the total square feet
answer :-
#Get the total sales
projectedTotalSale = float(input("Enter the projected amount of total sales : "))
#calculate the total profit
profit = projectedTotalSale * .23
#display the profit
print("profit will be :",format(profit , ',.2f'))
3.Land Calculation
One acre of land is equivalent to 43,560 square feet. Write a program that asks the user to enter the total square feet in a tract of land and calculates the number of acres in the tract.
Hint: divide the amount entered by 43,560 to get the number of acres.
answer :-
#Get the total square feet
totalSquareFeet = int(input("Enter the total square feet : "))
#calculate the total acres
totalAcre = totalSquareFeet / 43560
#display the total acres
print("total Acres will be :",format(totalAcre , ',.2f'))
4.Total Purchase
A customer in a store is purchasing five items. Write a program that asks for the price of each item, and then displays the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax is 6 percent.
answer :-
#ask price of each item
item1 = float(input("Enter the price of item1: "))
item2 = float(input("Enter the price of item2: "))
item3 = float(input("Enter the price of item3: "))
item4 = float(input("Enter the price of item4: "))
item5 = float(input("Enter the price of item5: "))
#calculate the subtotal of 5 items
subTotal = (item1 + item2 + item3 + item4 + item5)
#calculate the tax
salesTax = subTotal * 0.06
#calculate toal
total = subTotal + salesTax
#disply subtotal,saletax,total
print("sub total :",format(subTotal , ',.2f'))
print("sales tax :",format(salesTax , ',.2f'))
print("total :",format(total , ',.2f'))
5.. Distance Traveled
Assuming there are no accidents or delays, the distance that a car travels down the interstate can be calculated with the following formula:
Distance = Speed x Time
A car is traveling at 60 miles per hour. Write a program that displays the following:
• The distance the car will travel in 5 hours
• The distance the car will travel in 8 hours
• The distance the car will travel in 12 hours
answer :-
#use formula : Distance = Speed(mile per hour) x Time(hour) to
#calculate distance in each scenarios
#calculate distance if the car will travel in 5 hours
distance1 = 60 * 5
#calculate distance if the car will travel in 8 hours
distance2 = 60 * 8
#calculate distance if the car will travel in 12 hours
distance3 = 60 * 12
#display distances
print("The distance the car will travel in 5 hours :",distance1)
print("The distance the car will travel in 8 hours :",distance2)
print("The distance the car will travel in 12 hours :",distance3)
6. Sales Tax
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 4 percent and the county sales tax is 2 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the total sales tax).
Hint: use the value 0.02 to represent 2 percent, and 0.04 to represent 4 percent.
answer :-
#Get the total purchase
totalPurchase = float(input("Enter the total amount of purchase : "))
#calculate the state sales tax(4%)
stateTax = totalPurchase * .04
#calculate the county sales tax(2%)
countyTax = totalPurchase * .02
#calculate the total sales
totalSale =( totalPurchase + stateTax + countyTax )
#display the total purchase
print("Amount of the purchase :",format(totalPurchase , ',.2f'))
#display the state sales tax
print("Amount of the state sales tax :",format(stateTax , ',.2f'))
#display the county sales tax
print("Amount of the county sales tax :",format(countyTax , ',.2f'))
#display the total sales
print("total sales :",format(totalSale , ',.2f'))
7.Miles-per-Gallon
A car’s miles-per-gallon (MPG) can be calculated with the following formula:
MPG = Miles driven / Gallons of gas used
Write a program that asks the user for the number of miles driven and the gallons of gas used. It should calculate the car’s MPG and display the result.
#calculate the total acres
totalAcre = totalSquareFeet / 43560
#display the total acres
print("total Acres will be :",format(totalAcre , ',.2f'))
4.Total Purchase
A customer in a store is purchasing five items. Write a program that asks for the price of each item, and then displays the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax is 6 percent.
answer :-
#ask price of each item
item1 = float(input("Enter the price of item1: "))
item2 = float(input("Enter the price of item2: "))
item3 = float(input("Enter the price of item3: "))
item4 = float(input("Enter the price of item4: "))
item5 = float(input("Enter the price of item5: "))
#calculate the subtotal of 5 items
subTotal = (item1 + item2 + item3 + item4 + item5)
#calculate the tax
salesTax = subTotal * 0.06
#calculate toal
total = subTotal + salesTax
#disply subtotal,saletax,total
print("sub total :",format(subTotal , ',.2f'))
print("sales tax :",format(salesTax , ',.2f'))
print("total :",format(total , ',.2f'))
5.. Distance Traveled
Assuming there are no accidents or delays, the distance that a car travels down the interstate can be calculated with the following formula:
Distance = Speed x Time
A car is traveling at 60 miles per hour. Write a program that displays the following:
• The distance the car will travel in 5 hours
• The distance the car will travel in 8 hours
• The distance the car will travel in 12 hours
answer :-
#use formula : Distance = Speed(mile per hour) x Time(hour) to
#calculate distance in each scenarios
#calculate distance if the car will travel in 5 hours
distance1 = 60 * 5
#calculate distance if the car will travel in 8 hours
distance2 = 60 * 8
#calculate distance if the car will travel in 12 hours
distance3 = 60 * 12
#display distances
print("The distance the car will travel in 5 hours :",distance1)
print("The distance the car will travel in 8 hours :",distance2)
print("The distance the car will travel in 12 hours :",distance3)
6. Sales Tax
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 4 percent and the county sales tax is 2 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the total sales tax).
Hint: use the value 0.02 to represent 2 percent, and 0.04 to represent 4 percent.
answer :-
#Get the total purchase
totalPurchase = float(input("Enter the total amount of purchase : "))
#calculate the state sales tax(4%)
stateTax = totalPurchase * .04
#calculate the county sales tax(2%)
countyTax = totalPurchase * .02
#calculate the total sales
totalSale =( totalPurchase + stateTax + countyTax )
#display the total purchase
print("Amount of the purchase :",format(totalPurchase , ',.2f'))
#display the state sales tax
print("Amount of the state sales tax :",format(stateTax , ',.2f'))
#display the county sales tax
print("Amount of the county sales tax :",format(countyTax , ',.2f'))
#display the total sales
print("total sales :",format(totalSale , ',.2f'))
7.Miles-per-Gallon
A car’s miles-per-gallon (MPG) can be calculated with the following formula:
MPG = Miles driven / Gallons of gas used
Write a program that asks the user for the number of miles driven and the gallons of gas used. It should calculate the car’s MPG and display the result.
answer :-
#Get the number of miles driven
milesDriven = float(input("Enter the number of miles driven : "))
#Get the gallons of gas used
gasUsed = int(input("Enter the gallons of gas used : "))
#calculate the MPG
mpg = milesDriven * gasUsed
#display the car's MPG
print("car's MPG :",format(mpg , ',.2f'))
8.Tip, Tax, and Total
Write a program that calculates the total amount of a meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15 percent tip and 7 percent sales tax. Display each of these amounts and the total.
answer :-
#Get the total amount of meal purchase
totalMealPurchased = float(input("Enter the charge for the food : "))
#calculate the tip(15%)
tip = totalMealPurchased * .15
#calculate the sales tax(7%)
saleTax = totalMealPurchased * .07
#calculate the total sales
totalPurchased =( totalMealPurchased + tip + saleTax )
#display the total amount of meal purchase
print("Amount of the meal purchase :",format(totalMealPurchased , ',.2f'))
#display the tip
print("Amount of the tip :",format(tip , ',.2f'))
#display the sales tax
print("Amount of the sales tax :",format(saleTax , ',.2f'))
#display the total purchased
print("total purchased :",format(totalPurchased , ',.2f'))
9.Celsius to Fahrenheit Temperature Converter
Write a program that converts Celsius temperatures to Fahrenheit temperatures.
The formula is as follows:
F = (9/5) C + 32
The program should ask the user to enter a temperature in Celsius, and then display the temperature converted to Fahrenheit.
answer :-
#Get the temperatures in Celsius
tempInCelsius = float(input("Enter the temperatures in Celsius : "))
#convert temperature in celsius to Fahrenheit
celsiusToFahrenheit = ( ( (9 / 5 ) * tempInCelsius ) + 32 )
#displat the temperature Fahrenheit
print("temperature converted to Fahrenheit is :",celsiusToFahrenheit)
10.Stock Transaction Program
Last month Joe purchased some stock in Acme Software, Inc. Here are the details of the purchase:
• The number of shares that Joe purchased was 1,000.
• When Joe purchased the stock, he paid $32.87 per share.
• Joe paid his stockbroker a commission that amounted to 2 percent of the amount he paid for the stock.
Two weeks later Joe sold the stock. Here are the details of the sale:
• The number of shares that Joe sold was 1,000.
• He sold the stock for $33.92 per share.
• He paid his stockbroker another commission that amounted to 2 percent of the amount he received for the stock.
Write a program that displays the following information:
• The amount of money Joe paid for the stock.
• The amount of commission Joe paid his broker when he bought the stock.
• The amount that Joe sold the stock for.
• The amount of commission Joe paid his broker when he sold the stock.
• Display the amount of money that Joe had left when he sold the stock and paid his broker (both times). If this amount is positive, then Joe made a profit. If the amount is negative, then Joe lost money.
answer :-
print("Last month Joe purchased some stock in Acme Software, Inc")
print("********details of the purchased*******")
noOfShare = 1000
print("The number of shares that Joe purchased :",noOfShare)
paidPerShare = 32.87
print("he paid $"+str(paidPerShare)," per share")
paidOnShares = noOfShare * paidPerShare
print("total amount was paid by Joe on 1000 shares was : $"+ \
str(format(paidOnShares ,'.2f')))
brokerCommission1 = paidOnShares * .02
print("amount of commission joe paid when he bought the stock was : $" + \
str(format(brokerCommission1 , ',.2f')))
print()
print()
print("Two weeks later Joe sold the stock")
print("********details of the sale*******")
noOfShareSold = 1000
print("The number of shares that Joe sold was :",noOfShareSold)
soldPerShare = 33.92
print("he sold $"+str(soldPerShare),"per share")
totalAmountSold = noOfShareSold * soldPerShare
print("total amount was sold by Joe on 1000 shares was : $"+ \
str(format(totalAmountSold ,'.2f')))
brokerCommission2 = totalAmountSold * .02
print("amount of commission joe paid when he sold the stock was : $" + \
str(format(brokerCommission2 , ',.2f')))
balanceAmount = totalAmountSold - ( paidOnShares + \
brokerCommission1 + brokerCommission2 )
print("Amount of money Joe has left : $"+str(format(balanceAmount , ',.2f')))
if(balanceAmount > 0):
print("Joe made a profit")
else:
print("Joe lost his money ")
i will post chapter 4,5 very soon. any correction has to be made, you can make it as comments it will be appreciated.
Great Article
ReplyDeleteB.Tech Final Year Projects for CSE in Python
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in
Chennai
nice it given high light to me
ReplyDelete