Posts
Showing posts from 2020
DOUBLE PENDULUM ANIMATION PROBLEM
- Get link
- X
- Other Apps
from numpy import sin , cos import numpy as np import matplotlib.pyplot as plt import scipy.integrate as integrate import matplotlib.animation as animation G = 9.8 # acceleration due to gravity, in m/s^2 L1 = 1.0 # length of pendulum 1 in m L2 = 1.0 # length of pendulum 2 in m M1 = 1.0 # mass of pendulum 1 in kg M2 = 1.0 # mass of pendulum 2 in kg def derivs ( state , t ): dydx = np . zeros_like ( state ) dydx [ 0 ] = state [ 1 ] del_ = state [ 2 ] - state [ 0 ] den1 = ( M1 + M2 ) * L1 - M2 * L1 * cos ( del_ ) * cos ( del_ ) dydx [ 1 ] = ( M2 * L1 * state [ 1 ] * state [ 1 ] * sin ( del_ ) * cos ( del_ ) + M2 * G * sin ( state [ 2 ]) * cos ( del_ ) + M2 * L2 * state [ 3 ] * state [ 3 ] * sin ( del_ ) - ( M1 + M2 ) * G * sin ( state [ 0 ])) / den1 dydx [ 2 ] = state [ 3 ] den2 = ( L2 / L1 ) * den1 dydx [ 3 ] = ( - M2 ...
program to print sum of natural numbers between 1 to 7.
- Get link
- X
- Other Apps
program to calculate and print roots of a quadratic equation: ax²+bx+c=0
- Get link
- X
- Other Apps
import math print ("For quadnatic equation, ax**2+ bx+ c.6, enter coefficlents below") a=int( input ( "Enter a :") ) b°=int( input ( "Enter b ;")) c= int( input ("Enter c :")) 1f a==0: print (value of", a, ' should not be zero') print ("n Aborting !!!111") else: delta=b*b-4a*c if delta>0: root1=(-b+math.sart (delta)) / (2*a) root2 =(-b-math. sqrt (delta))/ (2*a) print ("Roots are REAL and UNEQUAL") print ("Root1=", root1, ", Root2=", root2) elif delta==0: root1=-b/ (2*a); print ("Roots are REAL and EQUAL") print ("Root1 ", root1, ", Root2 a", root1) else: print ("Roots are COMPLEX and IMAGINARY") Output For quadratic equation, ax*2 + bx...
program that reads two numbers and an arithmetic operator and displays the computed result.
- Get link
- X
- Other Apps
num1=float(input("Enter first number:")) num2=float(input("Enter second number:")) op=input("Enter operator[ + - * / % ]:") result=0 If op == '+': result=num1+num2 else op =='-': result=num1-num2 else op =='*': result=num1*num2 else op =='/': result=num1/num2 else op =='%': result=num1%num2 else: print ("Invalid operator!!") print(num1,op,num2,'=',result) Output Enter first number:5 Enter second number:2 Enter operator[ + - * / % ]: * 5.0*2.0=10.0
program to display a menu for calculating area of a circle or perimeter of a circle.
- Get link
- X
- Other Apps
radius=float(input("Enter radius of the circle:")) print("1.calculate area") print("2.calculate perimeter") Choice=int(input("Enter your choice (1or2):")) if choice == 1: area=3.14159*radius*radius print("area of circle with radius", radius,'is',area) else: perm=2*3.14159*radius print ("perimeter of circle with radius", radius,'is',perm) Output Enter radius of circle : 2.5 1.calculate area 2.calculate perimeter Enter your choice(1or 2):1 area of circle with radius 2.5 is 19.6349375
program to test the divisibility of a number with another number.
- Get link
- X
- Other Apps
Number 1 : int (input ("Enter first number:")) Number 2 : int (input ("Enter second number:")) remainder = number1%number 2 If remainder == 0 : Print(number1,"is divisible by", number 2) else : Print(number1,"is not divisible by", number 2) Output Enter first number : 119 Enter second number :3 119.0 is not divisible by 3.0 ============================== Enter first number : 119 Enter second number : 17 119.0 is divisible by 17.0
program to find the multiples of a number ( the divisor) out of given five numbers.
- Get link
- X
- Other Apps
Print ("Enter five numbers below") num1= float (input("First number:")) num2= float (input("Second number:")) num3= float (input("Third number:")) num4= float (input("Fourth number:")) num5= float (input("Fifth number:")) divisor= float (input("Enter divisor number:")) Count=0 print("Multiples of",divisir, "are:") remainder=num1%divisor if remainder ==0: print(num1,sep=" ") Count +=1 remainder=num2%divisor if remainder ==0: print(num2,sep=" ") Count +=1 remainder=num3%divisor if remainder ==0: print(num3,sep=" ") Count +=1 remainder=num4%divisor if remainder ==0: print(num4,sep=" ") Count +=1 remainder=num5%divisor if remainder ==0: print(num5,sep=" ") Count +=1 Print() Print(Count,"multiples of",divisor,"found") Output Enter five numbers below First ...
WAP to obtain temperature in Celsius and convert it into Fahrenheit using formula. °C×9/5+32=°F
- Get link
- X
- Other Apps
program to calculate BMI (body mass index) of a person.
- Get link
- X
- Other Apps
#to calculate BMI = Kg/m square Weight _in_kg = float (input("Enter weight in kg:")) Height_in_meter = float(input("Enter height in meter :")) Bmi = Weight_in_kg / ( Height_in_meter* Height_in_meter) Print("BMI is:", Bmi) Output Enter weight in kg : 66 Enter height in meter : 1.6 BMI is : 25.781249999999996
To find average number in python programming.
- Get link
- X
- Other Apps
# Get three test score round1 = int(input("Enter score for round 1: ")) round2 = int(input("\nEnter score for round 2: ")) round3 = int(input("\nEnter score for round 3: ")) # Calculate the average average = (round1 + round2 + round3) / 3 # Print out the test score print("\nThe average score is: ", average) Output: 4 37 64 Enter score for round 1: Enter score for round 2: Enter score for round 3: The average score is: 35.0
moving circle on canvas by tkinter
- Get link
- X
- Other Apps

#!/usr/bin/python from tkinter import * import time gui = Tk() var=IntVar() gui.geometry("800x800") c = Canvas(gui ,width=800 ,height=800) c.pack() oval = c.create_oval(5,5,60,60,fill='pink') a = 5 b = 5 for x in range(0 ,100): c.move(oval,a,b) gui.update() time.sleep(.01) gui.title("First title") gui.mainloop()
analog clock
- Get link
- X
- Other Apps

# import winsound from turtle import Turtle, Screen, Terminator from datetime import datetime screen = Screen() screen.mode('logo') screen.setup(700, 700) screen.title('Alarm Clock') tag_list = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] monat = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'June', 'July', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.'] FONT_SIZE = 14 FONT = ('Courier', FONT_SIZE, 'bold') BUTTON_SIZE = 40 CURSOR_SIZE = 20 def jump(turtle, distance): turtle.penup() turtle.forward(distance) turtle.pendown() def hand(turtle, laenge, spitze): turtle.fd(laenge * 1.10) turtle.rt(90) turtle.fd(spitze / 20.0) turtle.lt(120) turtle.fd(spitze) turtle.lt(120) turtle.fd(spitze) ...