Basic Programs in Py
Basic Programs in Py
print('Hello, world!')
=========
In the program below, we've used the + operator to add two numbers.
num1 = 15
num2 = 63
=============
============
==========
===============
ax2 + bx + c = 0, where
a, b and c are real numbers and
a ≠ 0
(-b ± (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)
#Source Code
# Solve the quadratic equation ax**2 + bx + c = 0
a = 1
b = 5
c = 6
Output
Enter a: 1
Enter b: 5
Enter c: 6
=============
# swap 2 variables
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)
===========
#To generate random number in Python, randint() function is used. This function is
defined in random module.
Source Code
import random
print(random.randint(0,9))
=============
#Example: Kilometers to Miles
# Taking kilometers input from the user
# conversion factor
conv_fac = 0.621371
# calculate miles
miles = kilometers * conv_fac
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))
Output