Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 3_numbers_exercise.py #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions Basics/Exercise/3_numbers/3_numbers_exercise.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
# Exercise
# 1. You have a football field that is 92 meter long and 48.8 meter wide. Find out total
# area using python and print it
# 1. You have a football field that is 92 meters long and 48.8 meters wide. Find out the total
# area using Python and print it
length=92
width=48.8
area=length*width
print("area of football field:",area) # Ans: 4489.599999999999

# 2. You bought 9 packets of potato chips from a store. Each packet costs 1.49 dollar
# and you gave shopkeeper 20 dollar.
# Find out using python, how many dollars is the shopkeeper going to give you back?
# 2. You bought 9 packets of potato chips from a store. Each packet costs 1.49 dollars
# and you gave the shopkeeper 20 dollars.
# Find out using Python, how many dollars the shopkeeper is going to give you back?
num_packets=9
cost_per_packet=1.49
total_cost=num_packets*cost_per_packet
money_paid=20
cash_back=money_paid-total_cost
print("Cash back:",cash_back) # Ans: 6.59
print("Cashback:",cash_back) # Ans: 6.59

# 3. You want to replace tiles in your bathroom which is exactly square and 5.5 feet
# is its length. If tiles cost 500 rs per square feet, how much will be the total
# cost to replace all tiles. Calculate and print the cost using python
# cost to replace all tiles? Calculate and print the cost using python
# Hint: Use power operator (**) to find area of a square
length=5.5
area=length**2 # area of square is length power 2
area=length**2 # area of the square is length power 2
cost=area*500
print("total cost for bathroom tiles replacement:",cost) # Ans: 15125.0

# 4. Print binary representation of number 17
num=17
print('Binary of number 17 is:',format(num,'b')) # Ans: 10001
print('Binary of number 17 is:',format(num,'b')) # Ans: 10001
#You can also solve this without using the built-in Python function format(). I have tried solving using a while loop. You can try something different.
num = 17
binary = ""
while num > 0:
x = num % 2
binary = str(x) + binary
num = num // 2
print(binary)