Posts

analog clock

Image
# 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) ...

program to input some numbers repeatedly and print their sum. the program ends when the users say no more to enter (normal termination) or program aborts when the number entered is less than zero.

DOUBLE PENDULUM ANIMATION PROBLEM

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.

Sum=0 For n in range(1,8):          sum+=n print("sum of natural numbers<=",n,'is',sum) Output Sum of natural numbers <= 7 is 28

program to print table of anumber, say 5

num=5 For a in range (1,11):   Print(num,'x'a,'=',num*a) Output 5×1=5 5×2=10 5×3=15 5×4=20 5×5=25 5×6=30 5×7=35 5×8=40 5×9=45 5×10=50

program to calculate and print roots of a quadratic equation: ax²+bx+c=0

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.

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.

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