KEMBAR78
Python Codes Collection | PDF | Applied Mathematics | Computer Engineering
0% found this document useful (0 votes)
3 views2 pages

Python Codes Collection

The document contains a collection of Python code snippets for various applications including a smart calculator, a student report card generator, a number guessing game, and a rock-paper-scissors game. Each code snippet demonstrates basic programming concepts such as loops, conditionals, and user input. The examples are designed to be easily understandable for beginners learning Python.

Uploaded by

Harsh Vardhan
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)
3 views2 pages

Python Codes Collection

The document contains a collection of Python code snippets for various applications including a smart calculator, a student report card generator, a number guessing game, and a rock-paper-scissors game. Each code snippet demonstrates basic programming concepts such as loops, conditionals, and user input. The examples are designed to be easily understandable for beginners learning Python.

Uploaded by

Harsh Vardhan
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/ 2

Python Codes Collection

Calculator with Loop Code


print("■ Smart Calculator ■")

while True:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
op = input("Choose operation (+, -, *, /): ")

if op == '+':
print("Result =", num1 + num2)
elif op == '-':
print("Result =", num1 - num2)
elif op == '*':
print("Result =", num1 * num2)
elif op == '/':
if num2 != 0:
print("Result =", num1 / num2)
else:
print("Error: Division by Zero!")
else:
print("Invalid Operation!")

again = input("Do you want to calculate again? (yes/no): ")


if again.lower() != "yes":
break

Student Report Code


print("■ Student Report Card Generator ■")

name = input("Enter Student Name: ")


roll = input("Enter Roll Number: ")

subjects = ["Math", "Science", "English", "History", "Computer"]


marks = []
total = 0
pass_status = "Pass"

for subject in subjects:


score = int(input(f"Enter marks for {subject} (out of 100): "))
marks.append(score)
total += score
if score < 40:
pass_status = "Fail"

percentage = total / len(subjects)

if percentage >= 90:


grade = "A+"
elif percentage >= 75:
grade = "A"
elif percentage >= 60:
grade = "B"
elif percentage >= 40:
grade = "C"
else:
grade = "Fail"

if all(m >= 90 for m in marks):


topper = "■ Topper!"
else:
topper = ""

print("\n========= REPORT CARD =========")


print("Name :", name)
print("Roll No. :", roll)
print("-------------------------------")
for i in range(len(subjects)):
status = "Pass" if marks[i] >= 40 else "Fail"
print(f"{subjects[i]} : {marks[i]} ({status})")
print("-------------------------------")
print("Total Marks:", total, "/ 500")
print("Percentage :", round(percentage, 2), "%")
print("Grade :", grade)
print("Result :", pass_status, topper)
print("===============================")

Guessing Code
import random

print("Welcome to the Number Guessing Game!")


print("I am thinking of a number between 1 and 10")

secret_number = random.randint(1, 10)

for attempt in range(3):


guess = int(input("Enter your guess: "))

if guess == secret_number:
print("■ Congratulations! You guessed it right!")
break
elif guess < secret_number:
print("Too low! Try again.")
else:
print("Too high! Try again.")
else:
print("■ Sorry, you lost. The number was", secret_number)

Rock-Paper-Scissors Code
import random

print("■ Rock - Paper - Scissors Game ■")


print("Choose: rock, paper, or scissors")

user_choice = input("Your choice: ").lower()


choices = ["rock", "paper", "scissors"]
computer_choice = random.choice(choices)

print("Computer chose:", computer_choice)

if user_choice == computer_choice:
print("It's a Tie!")
elif (user_choice == "rock" and computer_choice == "scissors") or (user_choice == "paper" and co
print("■ You Win!")
else:
print("■ You Lose!")

You might also like