[go: up one dir, main page]

0% found this document useful (0 votes)
8 views5 pages

Python Lab Practical-1

This document is a Python lab assignment submitted by Aryan Yadav, which includes seven programming tasks. The tasks involve generating a random number, converting kilometers to miles, checking the sign of a number, printing the Fibonacci sequence, finding the ASCII value of a character, shuffling a deck of cards, and displaying a calendar. Each task is accompanied by sample code and expected output.

Uploaded by

yadav1258ji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Python Lab Practical-1

This document is a Python lab assignment submitted by Aryan Yadav, which includes seven programming tasks. The tasks involve generating a random number, converting kilometers to miles, checking the sign of a number, printing the Fibonacci sequence, finding the ASCII value of a character, shuffling a deck of cards, and displaying a calendar. Each task is accompanied by sample code and expected output.

Uploaded by

yadav1258ji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PYTHON LAB ASSIGNMENT-1

Submitted To: Prof. Rahul Dubey


Submitted By: Aryan
yadav(0901cs231025)

1. Write a Python Program to Generate a Random Number.

import random

random_number = random.randint(1, 100)


print(“Random number between 1 and 100:” random_number)

OUTPUT:

2. Write a Python Program to Convert Kilometers to Miles.

kilometers = float(input(“Enter distance in kilometers : “))

miles = kilometers * 0.621371

print( kilometers,“kilometers is equal to”,miles,”miles”)

OUTPUT:

3. Write a Python Program to Check if a Number is Positive, Negative or 0.

number = float(input("Enter a number: "))

if number > 0:
result = "Positive"
elif number < 0:
result = "Negative"
else:
result = "Zero"

print(“The number is “,result)


OUTPUT:

4. Write a Python Program to Print the Fibonacci sequence

num = int(input("Enter the number of terms: "))

if num <= 0:
print("Please enter a positive integer")
elif num == 1:
print(0)
else:
n1, n2 = 0, 1
count = 0

if num > 0:
print("Fibonacci Series:", end = ' ')
while count < num:
print(n1, end=' ')
nth = n1 + n2
n1 = n2
n2 = nth
count += 1

OUTPUT:
5. Write a Python Program to Find ASCII Value of Character

char = input("Enter a character: ")


ascii_value = ord(char)

print(f"The ASCII value of '{char}' is {ascii_value}")

OUTPUT:

6. Write a Python Program to Shuffle Deck of Cards

import random

suits = ["Hearts", "Diamonds", "Clubs", "Spades"]


ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"]

deck = [f"{rank} of {suit}" for suit in suits for rank in ranks]

random.shuffle(deck)

print("Shuffled deck of cards:")


for card in deck:
print(card)
7. Write a Python Program to Display Calendar.
import calendar
year = int(input("Enter year: "))
month = int(input("Enter month (1-12): "))
print(calendar.month(year, month))

OUTPUT:

You might also like