Skip to content

Instantly share code, notes, and snippets.

View Mohamed2del's full-sized avatar
💭
WE ARE IN END GAME NOW

Mohamed adel mohamed Mohamed2del

💭
WE ARE IN END GAME NOW
View GitHub Profile
@Mohamed2del
Mohamed2del / 2.3.py
Last active June 1, 2022 02:50
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25).
hrs = input("Enter Hours:")
y = input("Enter the rate:")
x =float(hrs) * float(y)
print("Pay:",x)
@Mohamed2del
Mohamed2del / 3.1.py
Created June 9, 2018 15:06
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float()…
hrs = input("Enter Hours:")
h = float(hrs)
xx = input("Enter the Rate:")
x = float(xx)
if h <= 40:
print( h * x)
elif h > 40:
print(40* x + (h-40)*1.5*x)
@Mohamed2del
Mohamed2del / 3.3.py
Created June 9, 2018 15:09
Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table: Score Grade >= 0.9 A >= 0.8 B >= 0.7 C >= 0.6 D < 0.6 F If the user enters a value out of range, print a suitable error message and exit
score = input("Enter Score: ")
s = float(score)
x = 'Error'
if s >= 0.9:
x = 'A'
elif s >=0.8:
x='B'
elif s >=0.7:
x='C'
elif s >= 0.6:
@Mohamed2del
Mohamed2del / 4.6.py
Created June 9, 2018 15:10
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Award time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of time-and-a-half in a function called computepay() and use the function to do the computation. The function should return a value. U…
def computepay(h,r):
x=0
if h > 40.0:
x = r * 40.0 +(1.5*r*(h-40.0))
elif h <= 40 :
x= h*r
return x
hrs = float(input("Enter Hours:"))
@Mohamed2del
Mohamed2del / Exercise 1: loops
Created June 9, 2018 16:28
Write a program which repeatedly reads numbers until the user enters "done". Once "done" is entered, print out the total, count, and average of the numbers. If the user enters anything other than a number, detect their mistake using try and except and print an error message and skip to the next number.
num = 0
tot = 0.0
while True:
number = input("Enter a number")
if number == 'done':
break
try :
num1 = float(number)
except:
print('Invailed Input')
@Mohamed2del
Mohamed2del / 5.2.py
Created June 9, 2018 16:51
Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match…
largest = None
smallest = None
while True:
num = input("Enter a number: ")
if num == "done" : break
try : n = int(num)
except :
print('Invalid input')
continue
if largest is None:
@Mohamed2del
Mohamed2del / 6.5.py
Last active May 23, 2024 18:22
Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. Convert the extracted value to a floating point number and print it out.
text = "X-DSPAM-Confidence: 0.8475";
startPos = text.find(':')
piece = text[startPos+1:]
end = float(piece)
print(end)
@Mohamed2del
Mohamed2del / 7.1.py
Last active July 19, 2023 20:59
#File_processing 7.1 Write a program that prompts for a file name, then opens that file and reads through the file, and print the contents of the file in upper case. Use the file words.txt to produce the output below. You can download the sample data at http://www.py4e.com/code3/words.txt
fname = input("Enter file name: ")
try :
fh = open(fname)
except:
print('Cannot open the file ',fname ,'please try again')
quit()
for line in fh :
line = line.upper()
@Mohamed2del
Mohamed2del / 7.2.py
Created June 11, 2018 06:47
#File_Processing Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum()…
fname = input("Enter file name: ")
fh = open(fname)
count = 0
plus = 0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
startPos = line.find(':')
piece = line[startPos+1:]
end = float(piece)
plus = plus+end
@Mohamed2del
Mohamed2del / gist:b26f60950a9e30c78333ae7b77acab27
Created June 11, 2018 20:37
#File_processing For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words in alphabetical order.
fname = input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
word = line.rstrip().split()
for element in word:
if element in lst:
continue
else :
lst.append(element)