0% found this document useful (0 votes)
3 views

Activity 3

The document contains a series of Python activities that involve user input, conditional statements, loops, and basic data structures. Activities include accepting names, checking player eligibility based on age and gender, calculating discounts, and managing lists of names. Additionally, it covers dictionary lookups for word definitions and a function to calculate the sum of a series.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Activity 3

The document contains a series of Python activities that involve user input, conditional statements, loops, and basic data structures. Activities include accepting names, checking player eligibility based on age and gender, calculating discounts, and managing lists of names. Additionally, it covers dictionary lookups for word definitions and a function to calculate the sum of a series.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Activity 3

5. # Accepting first name and last name from the user

first_name = input("Enter your first name: ")

last_name = input("Enter your last name: ")

# Printing out the full name

print("Your full name is:", first_name, last_name)

Activity 4

age = int(input("Enter player's age: "))

gender = input("Enter player's gender (male/female): ").lower()

if 10 <= age <= 20 and gender == "female":

print("Player is eligible.")

else:

print("Player is not eligible.")

tank_size = float(input("How big is your tank in L? "))

tank_fullness = int(input("How full is your tank in %? "))

km_per_liter = float(input("How many km/L does your car get? "))

distance_to_next_station = 200

remaining_distance = distance_to_next_station - (tank_size * tank_fullness / 100 * km_per_liter)

if remaining_distance <= 0:

print("You need to buy gas here.")


else:

print("You can wait for the next station.")

Activity 5

purchase_price = float(input("Enter purchase price: "))

if purchase_price > 1000:

discount = purchase_price * 0.1

else:

discount = purchase_price * 0.02

final_price = purchase_price - discount

print("Discount applied:", discount)

print("Final price:", final_price)

Activity 6

Program: Looping Here's the output of the given Python statements:range(1, 8): [1, 2, 3, 4, 5, 6,
7]range(8): [0, 1, 2, 3, 4, 5, 6, 7]range(2, 9, 2): [2, 4, 6, 8]range(10, 0, -2): [10, 8, 6, 4, 2]

2.num = int(input("Enter a number: "))

for i in range(1, 11):

print(num, "x", i, "=", num * i)

Activity 7

****

****

****
****

****

****

Activity 8

# Part a

names = []

for i in range(5):

name = input("Enter a name: ")

names.append(name)

print("Original list of names:", names)

# Part b

sorted_names = sorted(names)

print("Sorted list of names:", sorted_names)

# Part c

replace_index = int(input("Enter the index of the name you want to replace (0-4): "))

new_name = input("Enter the new name: ")

names[replace_index] = new_name

print("Modified list of names:", names)

Activity 9

# Define a dictionary of word definitions

word_definitions = {

'python': 'A high-level programming language known for its simplicity and readability.',

'algorithm': 'A set of instructions designed to perform a specific task.',


'variable': 'A named storage location in a program.',

# Add more words and their definitions as needed

# Prompt the user to enter a word

word = input("Enter a word to look up its definition: ").lower()

# Look up the word in the dictionary

definition = word_definitions.get(word)

# Check if the word is found in the dictionary

if definition:

print("Definition:", definition)

else:

print("Sorry, the definition for '{}' is not found.".format(word))

Activity 10

def calculate_sum(n):

return (n * (n + 1)) // 2

# Prompt the user to enter the value of n

n = int(input("Enter the value of n: "))

# Call the function to calculate the sum

sum_of_series = calculate_sum(n)
# Print the result

print("Sum of the series:", sum_of_series)

You might also like