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

Grade-8-2 Python Programs

The document contains various Python programs suitable for Grade 8 students, demonstrating basic programming concepts such as conditional statements, loops, and user input. Key examples include determining if a number is positive, negative, or zero, grading student scores, converting Fahrenheit to Celsius, and implementing a countdown timer. Additional programs include a guessing game, password validation, triangle classification, and checking the product of three numbers.

Uploaded by

muhammednagy18
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)
4 views5 pages

Grade-8-2 Python Programs

The document contains various Python programs suitable for Grade 8 students, demonstrating basic programming concepts such as conditional statements, loops, and user input. Key examples include determining if a number is positive, negative, or zero, grading student scores, converting Fahrenheit to Celsius, and implementing a countdown timer. Additional programs include a guessing game, password validation, triangle classification, and checking the product of three numbers.

Uploaded by

muhammednagy18
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

Python Programs: Grade-8

number = int(input("Enter an integer: "))

if number == 0:

print("The number is zero.")

else:

if number > 0:

print("The number is positive.")

else:

print("The number is negative.")

score = float(input("Enter the student's score: "))


if 90 <= score <= 100:
print("Grade: A")
elif 80 <= score <= 89:
print("Grade: B")
elif 70 <= score <= 79:
print("Grade: C")
elif 60 <= score <= 69:
print("Grade: D")
elif score < 60:
print("Grade: F")
else:
print("Invalid score. Scores must be between 0 and 100.")
number = int(input("Enter an integer: "))
if number % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")

fahrenheit = 0
while fahrenheit != -1:
fahrenheit = float(input("Enter a temperature in Fahrenheit (or -1 to stop):
“))
if fahrenheit == -1:
print("Program terminated.")
else:
celsius = (fahrenheit - 32) * 5 / 9
print("The temperature in Celsius is:", celsius)

import time

# Take an integer input from the user


n = int(input("Enter an integer for the countdown: "))

# Start countdown
while n > 0:
print(n)
[Link](1) # Wait for 1 second
n -= 1 # Decrement the counter

print("Countdown finished!")
import random
# Generate a random number between 1 and 100
secret_number = [Link](1, 100)
print("I have chosen a number between 1 and 100.")

# Initialize the user's guess to None


guess = None
# Loop until the user guesses the correct number
while guess != secret_number:
# Take a guess from the user
guess = int(input("Make a guess: "))
# Provide hints to the user
if guess < secret_number:
print("Higher...")
elif guess > secret_number:
print("Lower...")

print("Congratulations! The number was:", secret_number)

correct_password = "python123"
password_guess = ""
while password_guess != correct_password:
password_guess = input("Please enter your password: ")
if password_guess == correct_password:
print("Login successful!")
else:
print("Incorrect password, try again.")
i=1
while i <= 5:
j=1
while j <= i:
# Print the column number
print(j, end=" ")
# Increment the inner loop counter
j=j+1
# Move to the next line after each row
print()
# Increment the outer loop counter
i=i+1

side1 = float(input("Enter the length of the first side: "))

side2 = float(input("Enter the length of the second side: "))

side3 = float(input("Enter the length of the third side: "))

if side1 == side2 == side3:

print("The triangle is equilateral.")

elif side1 == side2 or side2 == side3 or side1 == side3:

print("The triangle is isosceles.")

else:

print("The triangle is scalene.")


num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))

product = num1 * num2 * num3

if product > 0:
print("The product of the three numbers is positive.")
elif product < 0:
print("The product of the three numbers is negative.")
else:
print("The product of the three numbers is zero.")

You might also like