Simple Python Programs
Program1.py:
Enter name, age and address one by one and display them.
आईडी नंबर इंटर करें, नाम और वेतन एक-एक करके उन्हें प्रदर्शित करें।
name = "Gyancs" age = 19 address = "Lucknow, U.P. India" print ("Name: {} \nAge: {} \nAddress: {}.".format (name, age,address))
Output:
Name: Gyancs
Age: 19 Address: Lucknow, U.P. India
Program2.py:
Enter 3 numbers, and find their sum, average and display them.
3 नंबर दर्ज करें, और उनका योग, औसत खोजें और उन्हें प्रदर्शित करें।
a = int(input ("Enter a Number : ")) b= int(input ("Enter a Number : ")) c = int (input ("Enter a Number: ")) sum = a + b + c average = sum / 3 print ("Sum of three numbers is: ", sum) print ("Average of three numbers is: ", average)
Output:
Enter a Number : 10
Enter a Number : 20
Enter a Number : 30
Sum of three numbers is: 60
Average of three numbers is: 20.0
Program3.py:
Enter the radius of a circle and find the area.
एक वृत्त की रेडियस दर्ज करें और क्षेत्र का पता लगाएं।
# Python Program to find Area of Circle using Radius PI = 3.14 radius = float (input('Please Enter the radius of a circle: ')) area = PI * radius * radius circumference = 2 * PI * radius print(" Area of a Circle = %.2f" %area) print(" Circumference of a Circle = %.2f" %circumference)
Output:
Please Enter the radius of a circle: 2
Area of a Circle = 12.56
Circumference of a Circle = 12.56
Program4.py:
Python Program to find Area of Circle using Circumference
सर्कुलेशन का उपयोग करके सर्किल का क्षेत्रफल ज्ञात करने का पायथन प्रोग्राम
import math cference = float (input(' Please enter the circumference of a circle: ')) area = (cference * cference) / (4 * math.pi) print(" Area Of a Circle = %.2f" %area)
Output:
Please Enter the Circumference of a circle: 3
Area of a Circle = 0.72
Program5.py:
Add Two Numbers Provided by the User
उपयोगकर्ता द्वारा प्रदान किए गए दो नंबर जोड़ें
numl = input('Enter first number: ') num2 = input('Enter second number: ') # Add two numbers sum = float (numl) + float (num2) # Display the sum print ('The sum of {0} and {1} is {2}'.format (numl, num2, sum))
Output:
Enter first number: 2.3
Enter second number: 2
The sum of 2.3 and 2 is 4.3
Program6.py:
Enter a number and display its cube value.
एक नंबर दर्ज करें और इसका घन मान प्रदर्शित करें।
number = float (input(" Please Enter any numeric Value : ")) cube = number * number * number print ("The Cube of a Given Number {0} = {1}". format (number, cube))
Output:
Please Enter any numeric Value : 3
The Cube of a Given Number 3.0 = 27.0
Example7.py:
Solve Quadratic Equation
द्विघात समीकरण हल करें
The standard form of a quadratic equation is: ax2 + bx + c = 0, where a, b and care real numbers and a ≠0
दिव्घात समीकरण का मानक रूप ह ax2 + bx+c= 0, जहाँ, a, b और c वास्तविक संख्या है औरa ≠0
# Solve the quadratic equation ax** 2+ bx + c = 0 # import complex math module import cmath # To take coefficient input from the users a = float (input ('Enter a: ')) b = float (input('Enter b:')) c = float (input('Enter c: ')) # calculate the discriminant d = (b** 2) - (4* a*c) # find two solutions soll = (-b-cmath.sqrt (d))/(2*a) sol2 = (-b+cmath.sqrt (d))/(2*a) print ('The solution are {0} and {1}'.format (soll, sol2))
Output:
Enter a: 1.2
Enter b: 2.1
Enter c: 3
The solution are (-0.8750000000000001-1.3169567191065923j) and (-0.8750000000000001+1.3169567191065923j)
Example8.py:
Find the Square Root
स्क्वायर रूट का पता लगायें
# Note: change this value for a different result num = float (input('Enter a number: ')) num_sqrt = num ** 0.5 print ('The square root of %0.3f is %0.3f'% (num , num_sqrt))
Output:
Enter a number: 9
The square root of 9.000 is 3.000
Example9.py:
Swap Two Variables
स्वैप दो वैरियेबल
x = input ('Enter value of x: ') y = input ('Enter value of y: ') print ("x value : ",x, "y value : ",y) # create a temporary variable and swap the values temp = x x = y y = temp print('The value of x after swapping: {}'.format (x)) print('The value of y after swapping: {}'.format (y))
Output:
Enter value of x: 10
Enter value of y: 20
x value : 10 y value : 20
The value of x after swapping: 20
The value of y after swapping: 10
Example10.py:
Without Using Temporary Variable swapping
अस्थायी वैरियेबल स्वैपिंग का उपयोग किए बिना
In python programming, there is a simple construct to swap variables.
पायथन प्रोग्रामिंग में, वैरियेबल को स्वैप करने के लिए एक सरल निर्माण ।
a = 100 b = 20 print (a, b) a, b = b, a print (a, b)
Output
100 20
20 100
Example11.py:
Generate a Random Number
एक रैंडम नम्बर उत्पन्न करें
import random print (random.randint (0,9))
Output
8
Example12.py:
Convert Kilometers to Miles
किलोमीटर को मील्स में बदलना
kilometers = float (input ("Enter value in kilometers :")) miles = kilometers * 0.621371 print('%0.3f kilometers is equal to %0.3f miles' % (kilometers, miles))
Output
Enter value in kilometers: 5
5.000 kilometers is equal to 3.107 miles
Example13.py:
Convert Celsius to Fahrenheit
सेल्सियस को फॉरेनहाइट में बदलना
c = float (input ("Enter Celsius : ")) far = (c * 1.8) + 32 print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit!' % (c, far))
Output :
Enter Celsius : 36.9
36.9 degree Celsius is equal to 98.4 degree Fahrenheit
Chapter wise Model Paper Link
- Introduction to Web Design
- Editors
- HTML Basics
- CSS
- CSS Framework
- JavaScript and Angular JS
- Photo Editor
- Web Publishing and Browsing