Output_python
Output_python
Formatted Printing
1. 1, b = 1.5678, 10.5, 12.66
print("Radius = {:2f}, Length = {:2f}, Breadth = {:2f}".format(r, l, b))
print("Age = {:2d}, Salary = {:2f}".format(age, salary))
print("Name = {:10s}, Salary = {:2f}".format(name, salary))
2. name, age, salary = "Paleshita", 30, 3000.55
print(f"Name = {name}, Age = {age}, Salary = {salary:.2f}")
3. Aim - WAP to find circumference of circle and perimeter of rectangle.
4. r, l, b = int(input("Enter radius, length and breadth: ")).split())
circumference = 23.14r perimeter = 2(l+b)*
print(circumference) print(perimeter)
# Program to make line graph using matplotlib
import matplotlib.pyplot as plt
import numpy as np
a = [1, 2, 3, 4, 5, 6] b = [6, 7, 8, 7.3, 8, 9.4]
# Second plot with a and b data
plt.plot(a, b)
plt.xlabel("Semester -->") plt.ylabel("CGPA -->") plt.title("CGPA According to Semester")
plt.show()
# WAP to make bar graph using matplotlib
import matplotlib.pyplot as plt import numpy as np
a = np.array(['Science', 'Math', 'English', 'Hindi', 'Computer']) b = np.array([65, 94, 75, 59,
93])
plt.xlabel("Subject -->") plt.ylabel("Percentage -->") plt.bar(a, b)
plt.title("Horizontal Bar Graph") # for Vertical Bar Graph # plt.barh(a, b) # there is no need
of h
plt.show()
Aim: Write a program to calculate HCF.
def hcf(a, b):
while b != 0:
a, b = b, a%b
return a
Aim: WAP that obtains decimal value of binary numeric string for e.g. decimal
values up to ‘1111’ is 15
b = '1111'
i=0
while b:
i = i * 2 + (ord(b[0]) - ord('0'))
b = b[1:]
Aim: WAP in python sentence that uses every letter of the alphabet. Whether
a given string is a pangram
def is_pangram(s):
alphabet = set('abcdefghijklmnopqrstuvwxyz')
return alphabet <= set(s.lower())
print(is_pangram("The quick brown fox jumps over the lazy dog"))
print(is_pangram("Crazily fed vixens gobble up exquisite opal jewels"))
a = 10
b = 20
c = 30
s, p = cal_sum_prod(a, b, c)
print("Sum =", s)
print("Product =", p)
Aim: WAP to maintain names and phone numbers and print systematically in
tabular form.
Contact = {'abhinav': 9823307892, 'raj': 6745812345,
'ajay': 9823011245, 'Anil': 4766556778}
while b:
i = i * 2 + (ord(b[0]) - ord('0'))
b = b[1:]
Aim: WAP that generates the following output using for loop:
# Print Alphabets A to Z
for alpha in range(65, 91):
print(chr(alpha), end="")
print()
# Radius
print('radius = {0:10.2f}'.format(r))
Aim: Loop that prints from 1 to 10 using an infinite loop. All numbers should
get printed in the same line.
i=1
while True:
print(i, end=' ')
i += 1
if i > 10:
break
if n % 2 == 0:
print(n, "is even")
else:
print(n, "is odd")
while n > 0:
rem = n % 10
rev = (rev * 10) + rem
n //= 10
if original == rev:
print(n, "is Palindrome")
else:
print(n, "is Not Palindrome")
if n > 1:
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
print(n, "is not a prime number")
break
else:
print(n, "is a prime number")
else:
print(n, "is not a prime number")
radius = int(r)
length = int(l)
breadth = int(b)
print()
while b:
i = i * 2 + (ord(b[0]) - ord('0'))
b = b[1:]
# Data to plot
labels = ['BJP', 'AAP', 'Congress', 'BSP', 'TMC']
sizes = [19, 17, 13, 7, 5]
colors = ['orange', 'lightskyblue', 'beige', 'gold', 'red']
explode = (0.25, 0, 0, 0, 0) # explode 1st slice
# Plot
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%',
shadow=True, startangle=140, radius=1.2)
plt.axis('equal')
plt.show()
Aim: WAP to define a function called generate_sentences
def generate_sentences(subjects, verbs, objects):
sentences = []
for sub in subjects:
for verb in verbs:
for obj in objects:
sentence = sub + " " + verb + " " + obj
sentences.append(sentence)
return sentences