Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd6a76c

Browse files
addition.py
1 parent 109912f commit bd6a76c

File tree

10 files changed

+107
-0
lines changed

10 files changed

+107
-0
lines changed

‎Basic/additon.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This program adds two numbers
2+
3+
num1 = 1.5
4+
num2 = 6.3
5+
6+
# Add two numbers
7+
sum = float(num1) + float(num2)
8+
9+
# Display the sum
10+
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

‎Basic/area of triangle.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Python Program to find the area of triangle
2+
3+
a = 5
4+
b = 6
5+
c = 7
6+
7+
# Uncomment below to take inputs from the user
8+
# a = float(input('Enter first side: '))
9+
# b = float(input('Enter second side: '))
10+
# c = float(input('Enter third side: '))
11+
12+
# calculate the semi-perimeter
13+
s = (a + b + c) / 2
14+
15+
# calculate the area
16+
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
17+
print('The area of the triangle is %0.2f' %area)

‎Basic/km to miles.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Taking kilometers input from the user
2+
kilometers = float(input("Enter value in kilometers: "))
3+
4+
# conversion factor
5+
conv_fac = 0.621371
6+
7+
# calculate miles
8+
miles = kilometers * conv_fac
9+
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))

‎Basic/pro.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#addition of two numbers
2+
#input function is use for taking input from user
3+
a=input("Enter the first Number: ")
4+
b=input("Enter the second Number: ")
5+
## Add two numbers
6+
c=int(a) + int(b)
7+
# Display the sum
8+
print("Sun of",a,"and",b,"is Equal To",c)

‎Basic/quadratic.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# import complex math module
2+
import cmath
3+
a = float(input('Enter a: '))
4+
b = float(input('Enter b: '))
5+
c = float(input('Enter c: '))
6+
7+
# calculate the discriminant
8+
d = (b**2) - (4*a*c)
9+
10+
# find two solutions
11+
sol1 = (-b-cmath.sqrt(d))/(2*a)
12+
sol2 = (-b+cmath.sqrt(d))/(2*a)
13+
print('The solution are {0} and {1}'.format(sol1,sol2))

‎Basic/random no .py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Program to generate a random number between 0 and 9
2+
3+
# importing the random module
4+
import random
5+
6+
print(random.randint(0,9))

‎Basic/squar root.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Python Program to calculate the square root
2+
3+
# Note: change this value for a different result
4+
num = 8
5+
6+
# To take the input from the user
7+
#num = float(input('Enter a number: '))
8+
9+
num_sqrt = num ** 0.5
10+
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))

‎Basic/sr for real and complex.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Find square root of real or complex numbers
2+
# Importing the complex math module
3+
import cmath
4+
5+
num = 1+2j
6+
7+
# To take input from the user
8+
#num = eval(input('Enter a number: '))
9+
10+
num_sqrt = cmath.sqrt(num)
11+
print('The square root of {0} is {1:0.3f}+{2:0.3f}j'.format(num ,num_sqrt.real,num_sqrt.imag))

‎Basic/swap with tem.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Python program to swap two variables
2+
3+
x = 5
4+
y = 10
5+
6+
# To take inputs from the user
7+
#x = input('Enter value of x: ')
8+
#y = input('Enter value of y: ')
9+
10+
# create a temporary variable and swap the values
11+
temp = x
12+
x = y
13+
y = temp
14+
15+
print('The value of x after swapping: {}'.format(x))
16+
print('The value of y after swapping: {}'.format(y))

‎Basic/swap without tem.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#swaping without using temporary variable
2+
x = 5
3+
y = 10
4+
5+
x, y = y, x
6+
print("x =", x)
7+
print("y =", y)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /