Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Output_python

The document contains various Python programming tasks and examples, including calculating LCM and HCF, formatted printing, generating graphs with matplotlib, checking for prime numbers, and manipulating strings. It also includes functions for generating sentences, calculating simple interest, and validating palindromes. Additionally, it demonstrates input/output operations and various mathematical computations.

Uploaded by

kumbharpranav29
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Output_python

The document contains various Python programming tasks and examples, including calculating LCM and HCF, formatted printing, generating graphs with matplotlib, checking for prime numbers, and manipulating strings. It also includes functions for generating sentences, calculating simple interest, and validating palindromes. Additionally, it demonstrates input/output operations and various mathematical computations.

Uploaded by

kumbharpranav29
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Outputs

Aim: Write a program to calculate LCM.


def hcf(a,b):
while b != 0: a, b = b, a%b
return a
num1 = int(input("Enter the first number: ")) num2 = int(input("Enter the second number:
"))
lcm = int((num1*num2)/hcf(num1,num2))
print("The LCM of", num1, "and num2 is", lcm)

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

num1 = int(input("Enter the first number: "))


num2 = int(input("Enter the second number: "))

print("The HCF of", num1, "and", num2, "is", hcf(num1, num2))

Aim: WAP that Prints cell unique combination


i=1
while i <= 3:
j=1
while j <= 3:
k=1
while k <= 3:
if i != j and j != k and k != i:
print(i, j, k)
k += 1
j += 1
i += 1
Aim: WAP that generates the following output
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ZYXWVUTSRQPONMLKJIHGFEDCBA
for alpha in range(65, 91):
print(chr(alpha), end=' ')
print()
for alpha in range(90, 64, -1):
print(chr(alpha), end=' ')
print()

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:]

print("Decimal value =", str(i))

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"))

Aim: Mean, Max, and Min, and SD and Var in python


# Define variables
max_val = 100
min_val = 25
mean_val = 58
sd = 0.56
var = 0.9

# Print the values


print("Max Value:", max_val)
print("Min Value:", min_val)
print("Mean Value:", mean_val)
print("Standard Deviation:", sd)
print("Variance:", var)

Aim: WAP for product using call by method


def cal_sum_prod(x, y, z):
s=x+y+z
p=x*y*z
return s, p

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}

for name, cell_no in Contact.items():


print(f"Name: {name}, Cell No: {cell_no}")

Aim: WAP that obtains decimal value of binary numeric string


b = "1111"
i=0

while b:
i = i * 2 + (ord(b[0]) - ord('0'))
b = b[1:]

print("Decimal value =", str(i))

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()

# Print Alphabets Z to A in small case, only change that point


for alpha in range(122, 96, -1):
print(chr(alpha), end="")

Aim: WAP using format () method of string


r, l, b = 1.5678, 10.5, 12.66
name, age, salary = 'Rakshita', 30, 53000.55

# Print order by position:


print('radius = {2}, length = {1}, breadth = {0}'.format(b, l, r))
print('name = {0}, age = {1}, salary = {2}'.format(name, age, salary))

# Print order by desired index:


print('radius = {2:.2f}, length = {1:.2f}, breadth = {0:.2f}'.format(b, l, r))
print('name = {0}, age = {1}, salary = {2:.2f}'.format(name, age, salary))

# Print order in 15 columns name and 10 columns salary:


print('name = {0:15}, salary = {1:10.2f}'.format(name, salary))

# 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

Aim: Write a program that prints all unique combinations of 1, 2, and 3.


i=1
while i <= 3:
j=1
while j <= 3:
k=1
while k <= 3:
if i != j and j != k and k != i:
print(i, j, k)
k += 1
j += 1
i += 1

Aim: WAP to receive 3 integers using one call to input()


start, end, step = input("Enter the start, end, and step values: ").split()

for i in range(int(start), int(end) + 1, int(step)):


print(i, i**2, i**3)

for i in range(int(start), int(end) + 1, int(step)):


print("{:3d} {:3d} {:3d}".format(i, i**2, i**3))

Aim: WAP to check the number is even or odd


n = int(input("Enter a number: "))

if n % 2 == 0:
print(n, "is even")
else:
print(n, "is odd")

Aim: WAP to find the simple interest.


Principal = int(input("Enter Principal: "))
Rate = int(input("Enter Rate: "))
Time = int(input("Enter Time: "))

SI = (Principal * Rate * Time) / 100


print("Simple Interest is: ", SI)

Aim: WAP to check the number is Palindrome or not


n = int(input("Enter a number: "))
original = n
rev = 0

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")

Aim: Console Input and Output


Console Input:
First
name = input("Enter full name: ")
fname, mname, lname = input("Enter full name: ").split()
Second:
n1, n2, n3 = input("Enter three values: ").split()
n1 = int(n1)
n2 = int(n2)
n3 = int(n3)
print(n1 + 10, n2 + 20, n3 + 30)
Third:
data = input("Enter name, age, salary: ").split()
name = data[0]
age = int(data[1])
salary = float(data[2])
print("Name = ", name)
print("Age = ", age)
print("Salary = ", salary)
Console Output:
print("Hello world!")
Aim: WAP to calculate the temperature from Fahrenheit to Celsius and
Celsius to Fahrenheit.
f = int(input("Enter a temperature in Fahrenheit: "))
c = (f - 32) * 5 / 9
print("Temperature in Celsius:", c, "°C")

c = int(input("Enter a temperature in Celsius: "))


f = (c * 9 / 5) + 32
print("Temperature in Fahrenheit is:", f, "°F")

Aim: WAP to check if a number is prime or not.


import math

n = int(input("Enter a number: "))

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")

Aim: WAP using split function to print circumference and perimeter


r, l, b = input("Enter the radius, length and breadth: ").split()

radius = int(r)
length = int(l)
breadth = int(b)

circumference = 2 * 3.14 * radius


perimeter = 2 * (length + breadth)

print("The circumference is:", circumference)


print("The perimeter is:", perimeter)
Aim: WAP to print all alphabets using for loop.
for alpha in range(65, 91):
print(chr(alpha), end="")

print()

for alpha in range(122, 96, -1):


print(chr(alpha), end="")

Aim: WAP that obtains decimal value of binary numeric string.


b = "1111"
i=0

while b:
i = i * 2 + (ord(b[0]) - ord('0'))
b = b[1:]

print("Decimal value =", str(i))

Aim: WAP to make a pie chart plot using matplotlib


import matplotlib.pyplot as plt

# 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

subjects = ["He", "She", "They"]


verbs = ["loves", "hates"]
objects = ["TV serials", "Netflix"]

sentences = generate_sentences(subjects, verbs, objects)

for sentence in sentences:


print(sentence)

You might also like