0% found this document useful (0 votes)
75 views

Coding

This document contains multiple code snippets that demonstrate different programming concepts like loops, conditionals, functions, and input/output. Some of the code snippets include: 1) A program that calculates the ending time of an event given the starting time and duration in minutes. 2) A program that calculates income tax owed based on annual income and tax brackets. 3) A program that determines if a year is a leap year or common year. 4) Multiple examples of while loops including a number guessing game and a countdown.

Uploaded by

tayyab zafar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Coding

This document contains multiple code snippets that demonstrate different programming concepts like loops, conditionals, functions, and input/output. Some of the code snippets include: 1) A program that calculates the ending time of an event given the starting time and duration in minutes. 2) A program that calculates income tax owed based on annual income and tax brackets. 3) A program that determines if a year is a leap year or common year. 4) Multiple examples of while loops including a number guessing game and a countdown.

Uploaded by

tayyab zafar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

hour = int(input("Starting time (hours): "))

mins = int(input("Starting time (minutes): "))


dura = int(input("Event duration (minutes): "))
duration_hour = dura // 60
total_hours = hour + duration_hour
duration_mins = dura % 60
total_mins = mins + duration_mins
total_mins2 = total_mins % 60
total_hours2 = total_hours + (total_mins // 60)
total_hours3 = total_hours2 % 24
print("Event ends at :", total_hours3,":",total_mins2)

income = float(input("Enter the annual income: "))


if income < 85528:
tax = (income * 0.18) - 556.2
if tax < 0:
tax = 0.0
else:
tax = 14839.2 + ((income - 85528)*0.32)
tax = round(tax, 0)
print("The tax is:", tax, "thalers")

year = int(input("Enter a year: "))


if year % 4 != 0:
print ("Common Year")
elif year % 100 != 0:
print ("Leap Year")
elif year % 400 != 0:
print ("Common Year")
else:
print ("Leap Year")

secret_number = 777
print("""+===================================================== +
| Welcome to my game, muggle! Enter an integer number |
| and guess what number I've picked for you. |
| So, what is the secret number? |
+===================================================== +""")
number = int(input())
while secret_number != number:
print ("Ha ha! You are stuck in my loop, Try again")
number = int(input())

print ("Well done, muggle! You are free now")

import time

for i in range (1, 6):


print (i, " Mississippi")
time.sleep(1)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

counter = 1
secret_word = "chupacabra"
word = input ("Guess the secret word:")
while word != secret_word:
input ("Yor guess is wrong, Try again :")
if word == "chupacabra":
break
counter += 1
print ("You guessed the word in",counter,"attempts", " \n Now you have successfully left the loop")

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
user_word = input("Enter the word :")
user_word = user_word.upper()
for letter in user_word:
if letter == "A":
continue
elif letter == "E":
continue
elif letter == "I":
continue
elif letter == "O":
continue
elif letter == "U":
continue
else:
word_without_vowels = letter
print(word_without_vowels,"\n")

blocks = int(input("Enter the number of blocks: "))


counter = 1
height = 0
block = 0
while block < blocks:
block = block + counter
counter += 1
if (box > blocks):
break
height += 1
print("The height of the pyramid:", height)

steps = 0
c0 = int(input("Enter non-negative and non-zero integer number :"))
while c0 != 1:
if c0 % 2 == 0:
c0 = c0 / 2
print(int(c0))
steps = steps + 1
else:
c0 = 3 * c0 + 1
print(int(c0))
steps = steps + 1
print("Steps = ",steps)

You might also like