cs1.pdf
cs1.pdf
cs1.pdf
print('Hello, world!')
Output
Hello, world!
num1 + num2
Output
The program below calculates the sum of two numbers entered by the user.
float(num1) + float(num2)
Output
Output
a =5
b=6
c =7
s = (a + b + c) / 2
Output
cmath
a=1b
=5c=
(b**2) - (4*a*c)
cmath.sqrt(d))/(2*a) sol2 = (-
b+cmath.sqrt(d))/(2*a)
Output
Enter a: 1 Enter
b: 5
Enter c: 6
x = 5 y = 10
temp = x x = y
y = temp
print('The value of x after swapping: {}'.format(x)) print('The
Output
numberone = 29
numbertwo = 13
numberone+numbertwo
# printing the result of sum of two numbers print("Adding the given two numbers",
numberone-numbertwo
numberone*numbertwo
numberone+numbertwo
Output:
Adding the given two numbers 29 + 13 = 42
We’ll write a program that produces a random number between a specific range.
random
random.randint(1, 450)
Output:
42.5
checkNumber(given_Num):
# if the above conditions are not satisfied then the given number is zero else:
# given numbers #
given number 1
given_num1 = 169
# passing the given number to checkNumber Function which prints the type of
number(+ve,-ve,0) checkNumber(given_num1) # given number 2 given_num1 = -374
# passing the given number to checkNumber Function which prints the type of
number(+ve,-ve,0) checkNumber(given_num1) # given number 3 given_num1 = 0
# passing the given number to checkNumber Function which prints the type of
number(+ve,-ve,0) checkNumber(given_num1) Output:
checkNumber(given_Num):
== 0):
# given numbers #
given number 1
given_num1 = 169
checkNumber(given_num1)
26
checkNumber(given_num1) Output:
2024 if (given_year % 4)
== 0: if (given_year %
100) == 0: if (given_year
% 400) == 0:
's'
given_marks = 68 markGrade =
print("Fail")
Output: grade
Example 15: Python program to print the sum of all numbers in the given range
# Python program to print the sum of all numbers in the given range
lower_range = 17 # given
upper_range = 126
17
126
Iterate from lowe limit range to upper limit range for numb in
print(numb) Output:
18
20
..124
126
given_rows = 15 for i in
range(given_rows+1): for j in
print() Output:
**
** *
** * *
** * * *
** * * * *
** * * * * *
** * * * * * *
** * * * * * * *
** * * * * * * * *
** * * * * * * * * *
** * * * * * * * * * *
** * * * * * * * * * * *
** * * * * * * * * * * * *
** * * * * * * * * * * * * *
Output:
12
123
1234
12345
123456
1234567
12345678
123456789
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12 13
1 2 3 4 5 6 7 8 9 10 11 12 13 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Python program to print the all the fibonacci numbers in the given range
13
21
34
55
89
144
233
377
610
987
49
..47
48
49