Skip to content

Instantly share code, notes, and snippets.

View hareom284's full-sized avatar
🔍
I do what I love.

Hare Om hareom284

🔍
I do what I love.
View GitHub Profile
@hareom284
hareom284 / 3.1.py
Last active July 22, 2020 15:39
3.1 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 floa…
hrs = int(input("Enter Hours:"))
rate = input("Enter rate")
rate = float(rate)
if hrs>40 :
print(rate*40 + (hrs-40)*1.5*rate)
@hareom284
hareom284 / 3.3.py
Last active July 16, 2020 07:43
3.3 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. For the test, enter a…
score = input("Enter Score")
try:
score = float(score)
except :
print("Please Enter Valid Input")
quit()
if score >= 0.9 :
print("A")
elif score>=0.8:
print("B")
@hareom284
hareom284 / 4.6.py
Created July 16, 2020 09:06
4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation.…
def computepay(h,r):
if h>40 :
return 40 * r + (h-40)*r*1.5
hrs = input("Enter Hours:")
rate = input("Enter rate")
try :
hrs = float(hrs)
rate = float(rate)
except :
@hareom284
hareom284 / 5.2.py
Created July 17, 2020 05:29
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 :
num = int(num)
if (largest==None) :
largest = num
@hareom284
hareom284 / 6.5.py
Last active July 21, 2020 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"
start = text.find('0')
end = text[start:29]
end = float(end)
print(end)
@hareom284
hareom284 / 7.1.py
Created July 22, 2020 14:57
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.
fname = input("Enter file name: ")
try :
fh = open(fname)
except:
print(fname," files does not exit .Enter valid file names")
quit()
for line in fh :
line =line.rstrip()# for removing newline from the letter
print(line.upper())
@hareom284
hareom284 / 7.2.py
Created July 22, 2020 15:27
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() function or a va…
fname = input("Enter file name: ")
fh = open(fname)
count = 0
total = 0.0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
count = count + 1
line = line[20:]
line = float(line)
total = total+line
@hareom284
hareom284 / cash.c
Created August 4, 2020 16:47
Harvard summer 2020 week 1
#include<stdio.h>
#include<cs50.h>
#include<math.h>
int main(void)
{ float dollars=0;
do
{
dollars = get_float("Chang owned:");
}while(dollars<0);
#include<stdio.h>
#include<cs50.h>
#include<string.h>
#include<math.h>
void Count(string text);
void print(double index);
double Letter = 0.0;
double Sentence = 0.0;
double words =1.0;
int main(void)
@hareom284
hareom284 / 8.4.py
Created August 10, 2020 17:56
8.4 Open the file romeo.txt and read it line by line. 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…
fname = input("Enter file name: ")
try:
fh = open(fname)
lst = list()
for line in fh:
lst.append( line.split())
newlist = sum(lst,[])
newlist.sort()
print([newlist[i] for i in range(len(newlist)) if i == newlist.index(newlist[i])])
except :