Coding Things

Stuff

#write a program that produces the following output. the user is asked to input any number. number=int(input("Put in any number: ")) f=number*6 if f>=600: print("Your number is too high. Put in another number.") elif f<=600: print("Your answer is "+str(f)) #Ask the user to input an amount in days. Convert number of days to seconds. Hint: Convert days to hours, hours to minutes, minutes to seconds day=int(input("Please put in a number of days that you want to convert to seconds: ")) x=day*24 y=x*60 z=y*60 print("It is "+str(z)+"seconds.") #write a python program which iterates the integers from 1 to 50. for multiples of three print "fizz" instead of the number and for the multiples of five print "Buzz". #For numbers which are multiples of both three and five print "FizzBuzz" for x in range(0,51,1): if x%3==0 and x%5==0: print("FizzBuzz") elif x%5==0: print("Buzz") elif x%3==0: print("Fizz") #write a python statement to find those numbers which are divisible by 7 and divisible by 5, between 1500 to 2700 for x in range(1499,2701,1): if x%7==0 and x%5==0: print(x) #print statements print("Hello") #Creating variables x=10 name="Rosie" #ask the user for input school=input("What is your school name?") print("I go to "+school) #collecting whole numbers from the user number=int(input("Enter a whole number:")) #Collecting decimal numbers number2=float(input("Enter a decimal:")) # 1)create a while loop from 1 to 150 skipping by 5 number=0 while number <= 150: print(number) number=number+5 # 2)create a for loop from 1 to 150 skipping by 3 for x in range(0,150,3): print(x) # 3)create a while loop from 1 to 200 printing all numbers except multiples of 4 for x in range(2,101,1): if x%4!=0: print(x) # 4)create a program which will ask for your recent exam score out of 60 and tell you what grade you got #A-90% and above #B-80% to 89.9 #C-70% to 79.99% number3=float(input("Enter your test score out of 60 using decimals:")) x=number3/60 y=x*100 print(y) if y>90: print("You got an A! Good Job!") elif y>80 and y<89.99: print("You got a B! Good Job") elif y>70 and y<79.99: print("You got a C! Good Job") elif y>60 and y<69.99: print("You got a D! Try Harder Next Time") elif y<59.9999: print("You got a F! You failed the test!") #write a Python program to calculate a dog's age in dog years #For the first 2 years, a dog year is equal to 10.5 years. #after that, it equals 4 years number4=float(input("Please enter your dog's age in decimals:")) if number4<=2.999999999: y=number4*10.5 print(y) print("Your dog's age is "+str(y)) elif number4>=3: z=number4*4 c=z+10.5*2 print(c) print("Your dog's age is "+str(c)) #Write a python program that asks the user to input a whole number in a variable called numb1. then the program prints everything from 1 to numb1 Numb1=int(input("Please insert a number: ")) for r in range(0,Numb1,1): print(r)

3 number calculator

3 number calculator

num1 = float(input("Enter a number ")) num2 = float(input("Enter a number ")) op1 = input("Enter operation") if op1 == "/": x = num1 / num2 print(num1 / num2) num3 = float(input("Enter a number ")) op2 = input("Enter operation") if op2 == "/": print(x / num3) if op2 == "*": print(x * num3) if op2 == "+": print(x + num3) if op2 == "-": print(x - num3) if op1 == "*": x = num1 * num2 print(num1 * num2) num3 = float(input("Enter a number ")) op2 = input("Enter operation") if op2 == "/": print(x / num3) if op2 == "*": print(x * num3) if op2 == "+": print(x + num3) if op2 == "-": print(x - num3) if op1 == "+": x = num1 + num2 print(num1 + num2) num3 = float(input("Enter a number ")) op2 = input("Enter operation") if op2 == "/": print(x / num3) if op2 == "*": print(x * num3) if op2 == "+": print(x + num3) if op2 == "-": print(x - num3) if op1 == "-": x = num1 - num2 print(num1 - num2) num3 = float(input("Enter a number ")) op2 = input("Enter operation") if op2 == "/": print(x / num3) if op2 == "*": print(x * num3) if op2 == "+": print(x + num3) if op2 == "-": print(x - num3) num3 = float(input("Enter a number ")) op2 = input("Enter operation") if op1 == "/": print(num1 / num2) if op1 == "*": print(num1 * num2) if op1 == "+": print(num1 + num2) if op1 == "-": print(num1 - num2)

Turtle graphics drawing

Make a cool triangle


from turtle import * bgcolor("salmon") color("cyan") steps = 60 for x in range(0,10,1): forward(steps) right(120) steps = steps + 10

Turtle Graphics: drawing a house

from turtle import * bgcolor("salmon") color("black") shape("turtle") forward(200) right(90) forward (200) right (90) forward (200) right (90) forward(200) right(45) forward (150) right(95) forward (150) penup() right (90) forward (100) left (45) pendown() forward (25) left(90) forward (25) left(90) forward (25) left (90) forward (25) penup() forward (60) left (90) pendown() left(90) forward (25) right (90) forward (25) right(90) forward (25) right(90) forward (25) right (180) penup() forward (100) left (90) forward (40) pendown () forward (20) left (90) forward (35) left (90) forward (20) left (90) forward (35)

SAT/ ACT Scores

print ("This program compares two applicants") print ("Determine which one seems like the stronger applicant") y = int(input("(do you have 1) SAT scores 2) ACT scores?")) if y == 1: print ( " I will calculate your SAT score.") Math = int(input (" What is your SAT math score?")) Reading = int(input (" What is your Critical Reading score?")) Writing = int(input ("What is your Writing score?")) x = (2*Math+Reading+Writing)/32 print (x) OverallGPA= float(input("What is your overall GPA?")) MaxGPA = int(input("What is your max GPA?")) TranscriptMultiplier= float(input("What is your Transcript Multiplier?")) y= (OverallGPA/MaxGPA)*100*TranscriptMultiplier print (y) if y == 2: print ( "I will calculate your ACT score.") English= int(input (" What is your ACT english score?")) Math= int(input ("What is your ACT math score?")) Reading= int(input ("What is your ACT reading score? ")) Science= int(input ("What is your ACT science score? ")) t = (English+2*Math+Reading+Science)/1.8 print(t) actual = float(input (" What is your actual GPA score?")) Max = float(input (" What is your max GPA score?")) TranscriptMultiplier= float(input("What is your transcript multiplier?")) n= (actual/Max)*100*TranscriptMultiplier print(n)

homework/exam grade calculator

print:("This program read exam/homework scores and reports your overall course grade.") weight = int(input("Enter the weight:")) score= int(input("Score earned?")) scoreshifted=int(input("Were scores shifted")) if scoreshifted ==1: shiftAmount = int(input("Enter a shift amount: ")) score= score +shiftAmount print("totalscore = " + str(score) + "/ 100")

Guessing game

This is the code for the guessing game I'm making.

import random n = random.randint(1, 100) guess = int(input("Enter an integer from 1 to 99: ")) while n != ("guess"): print if guess < n: print("guess is low") guess = int(input("Enter an integer from 1 to 99: ")) elif guess > n: print("guess is high") guess = int(input("Enter an integer from 1 to 99: ")) else: print("you guessed it!") break print

AI Broken Down

This is one of my favorite videos describing math behind AI, specifically how a neural network is trained.


Grading Software

Here is a python program where you can input test grades and receive your overall score.

eight = int(raw_input("What is your weight")) ScoreEarned = int(raw_input("What is your score")) Extracredit = int(raw_input("Were scores shifted")) if Extracredit == 1: print("Your score was shifted") if Extracredit == 2: print("Your score was not shifted") totalpoints = (ScoreEarned) print("totalpoints = " + str(ScoreEarned) + " / 100") x = 100.0/ Weight weightedscore1 = ScoreEarned / x print(weightedscore1) print("This software will read your final test score") print(" Final:") Weight = int(raw_input("weight(1-100)?" )) ScoreEarned = int(raw_input("Score Earned?" )) Scoreshifted = int(raw_input("Were scores shifted (1=yes, 2= no)? ")) if Scoreshifted == 1: Amount= int(raw_input("By how much were they shifted?" )) totalpoints = ScoreEarned print("totalpoints= " + str(ScoreEarned) + " / 100") x = 100.0/Weight print(x) Weightedscore2 = ScoreEarned / x print(Weightedscore2) print("This software will read your homework grade") print("Homework:") Weight = int(raw_input("Weight(1-100)?")) Numofassignments = int(raw_input("Number of assignments?")) total = 0 totalpoints = 0 for i in range(1, Numofassignments+1, 1): Score = int(raw_input("What was your score for this assignment ?" + str(i))) total = total + Score Maxpoints = int(raw_input("What was the max score for this assignment ?" + str(i))) totalpoints = totalpoints + Maxpoints print("total points = " + str(total) + " / " + str(totalpoints)) percent = total / totalpoints wScore = percent * Weight print("Weightedscore3 = " + str(wScore) + " / " + str(Weight)) OverallPercentage = weightedscore1 + Weightedscore2 + wScore print(OverallPercentage)

python sorting program

a = [2, 3, 1, 7, 5, 4] min = 1000 index = -1 for start in range(0, len(a) - 1): min = 1000 for i in range(start, len(a)): if a[i] < min: min = a[i] index = i #swap temp = a[start]; a[start] = a[index]; a[index] = temp; print(a)

ACT or SAT

This code calculates ACT and SAT scores and GPA.

i= int(input("Do you have 1) SAT scores or 2) ACT scores?")) if i==1: Math=int(input("SAT math?")) Criticalreading= int(input("SAT reading")) Writing=int(input("SAT Writing")) X= (2*Math+Criticalreading+Writing)/32 print(X) OverallGPA=float(input("What is your overall GPA?")) MaxGPA=float(input("What is the max GPA")) TranscriptMult=float(input("Transcript Multiplier?")) GPA1=OverallGPA/MaxGPA*100*TranscriptMult print("GPA score:") print(GPA1) elif i==2: English=int(input("ACT English")) Math=int(input("ACT math?")) Reading=int(input("ACT reading")) Science=int(input("ACT science")) Y= (English+2*Math+Reading+Science)/1.8 print(Y) OverallGPA=float(input("What is your overall GPA?")) MaxGPA=float(input("What is the max GPA")) TranscriptMult=float(input("Transcript Multiplier?")) GPA2=OverallGPA/MaxGPA*100*TranscriptMult print("GPA score:") print(GPA2) i= int(input("Do you have 1) SAT scores or 2) ACT scores?")) if i==1: Math=int(input("SAT math?")) Criticalreading= int(input("SAT reading")) Writing=int(input("SAT Writing")) X= (2*Math+Criticalreading+Writing)/32 print(X) OverallGPA=float(input("What is your overall GPA?")) MaxGPA=float(input("What is the max GPA")) TranscriptMult=float(input("Transcript Multiplier?")) GPA1=OverallGPA/MaxGPA*100*TranscriptMult print("GPA score:") print(GPA1) elif i==2: English=int(input("ACT English")) Math=int(input("ACT math?")) Reading=int(input("ACT reading")) Science=int(input("ACT science")) Y= (English+2*Math+Reading+Science)/1.8 print(Y) OverallGPA=float(input("What is your overall GPA?")) MaxGPA=float(input("What is the max GPA")) TranscriptMult=float(input("Transcript Multiplier?")) GPA2=OverallGPA/MaxGPA*100*TranscriptMult print("GPA score:") print(GPA2) Overallscore1=GPA1+X Overallscore2=GPA2+Y print("First applicant overall score:") print(Overallscore1wel) print("Second applicant overall score:") print(Overallscore2) if Overallscore1<Overallscore2: print("The first applicant seems to be better") if Overallscore1>Overallscore2: print("The second applicant seems to be better") if Overallscore1==Overallscore2: print("They are the same in value")

Fractions

this adds,subtracts,multiplies,divides fractions and returns the fraction

class Fraction: '''represents fractions''' def __init__(self,num,denom): self.num=num self.denom=denom '''Fraction(num,denom) -> Fraction creates the fraction object representing num/denom''' if denom == 0: # raise an error if the denominator is zero raise ZeroDivisionError def __str__(self): lst=[] if self.num == 0: return "0" if self.num<0: neg=-self.num for i in range(1,neg+1): if self.num/i==self.num//i and self.denom/i==self.denom//i: lst.append(-1*i) minimum=min(lst) smplfiednum=self.num//minimum smplfieddenom=self.denom//minimum return str(smplfiednum)+'/'+str(smplfieddenom) elif self.num>0: for n in range(1,self.num+1): if self.num/n==self.num//n and self.denom/n==self.denom//n: lst.append(n) maximum=max(lst) smplfiednum=self.num//maximum smplfieddenom=self.denom//maximum return str(smplfiednum)+'/'+str(smplfieddenom) def __float__(self): return self.num/self.denom def add(self, other): newdenom = self.denom*other.denom newnum = (self.num*other.denom)+(other.num*self.denom) #self.denom=newdenom #self.num=newnum return Fraction(newnum, newdenom) def sub(self, other): newdenom = self.denom*other.denom newnum = (self.num*other.denom)-(other.num*self.denom) #self.denom=newdenom #self.num=newnum return Fraction(newnum,newdenom) def mul(self, other): newdenom = self.denom*other.denom newnum = self.num*other.num #self.denom=newdenom #self.num=newnum return Fraction(newnum,newdenom) def div(self, other): newdenom = self.denom*other.num newnum = self.num*other.denom #self.denom=newdenom #self.num=newnum return Fraction(newnum,newdenom) def eq(self,other): if self.denom/other.denom==self.num/other.num: return True else: return False # examples #getting p p = Fraction(3,6) print(p) # should print 1/2 q = Fraction(10,-60) print(q) # should print -1/6 r = Fraction(-24,-48) print(r) # should also print 1/2 x=float(p) print(x) # should print 0.5 ### if implementing "normal" arithmetic methods print(p.add(q)) # should print 1/3, since 1/2 + (-1/6) = 1/3 print(p.sub(q)) # should print 2/3, since 1/2 - (-1/6) = 2/3 print(p.sub(p)) # should print 0/1, since p-p is 0 print(p.mul(q)) # should print -1/12 print(p.div(q)) # should print -3/1 print(p.eq(r)) # should print True print(p.eq(q)) # should print False
1 ... 33 34 35