0% found this document useful (0 votes)
16 views6 pages

Half Yearly - P2 - 2023 - MS

Uploaded by

clumsydaisyfx
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)
16 views6 pages

Half Yearly - P2 - 2023 - MS

Uploaded by

clumsydaisyfx
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/ 6

1.

Page
1
2. DECLARE N as INTEGER
DECLARE D, Cost AS FLOAT

OUTPUT ("How many tickets would you like to buy?")


INPUT N

WHILE N >= 1 AND N < 26 DO


IF N < 10 THEN
D=0
ELSE IF N < 20 DO THEN
D = 0.1
ELSE
D = 0.2
END IF

Cost = N * (1-D)
OUTPUT "Your tickets cost", Cost)

---------- Python ---------------

# Declare variables
N=0
D = 0.0
Cost = 0.0

# Get user input


N = int(input("How many tickets would you like to buy?"))

# Check if the input is within the valid range


while N >= 1 and N < 26:
# Determine the discount based on the number of tickets
if N < 10:
D=0
elif N < 20:
D = 0.1
else:
D = 0.2

# Calculate the cost after discount


Cost = N * (1-D)
print("Your tickets cost", Cost)
else:
print("Invalid number of tickets. Please enter a number between 1 and 25.")
2
Page
3. INPUT Grade

IF Grade = "A" THEN


OUTPUT "Excellent"
ELSE IF Grade = "B" THEN
OUTPUT "Good"
ELSE IF Grade = "C" THEN
OUTPUT "Average"
ELSE
OUTPUT "Improvement is needed"
END IF

4. Total ← 0
OUTPUT "Enter value for mark, -1 to finish "
INPUT Mark

WHILE Mark <> -1 DO


Total ← Total + Mark
OUTPUT "Enter value for mark, -1 to finish"
INPUT Mark
ENDWHILE

5. OUTPUT "Please enter name to find "


INPUT Name
Found ← FALSE
Counter ← 1

REPEAT
IF Name = StudentName[Counter] THEN
Found ← TRUE
ELSE
Counter ← Counter + 1
ENDIF
UNTIL Found OR Counter > ClassSize

IF Found THEN
OUTPUT Name, " found at position ",
Counter, " in the list."
ELSE OUTPUT Name, " not found."
ENDIF
3
Page
============ PYTHON ===================

# Assuming StudentName and ClassSize are defined elsewhere in your code

print("Please enter name to find ")


Name = input()

Found = False
Counter = 1

while not Found and Counter <= ClassSize:


if Name == StudentName[Counter]:
Found = True
else:
Counter += 1

if Found:
print(Name, " found at position ", Counter, " in the list.")
else:
print(Name, " not found.")

6. values = [27, 19, 36, 42, 16, 89, 21, 16, 55, 72]
total = 0

for value in values:


total += value

print("The total is:", total)


4
Page
7. values = [27, 19, 36, 42, 16, 89, 21, 16, 55, 72]

# Initialize variables
count = 0
total = 0
max_value = values[0]
min_value = values[0]

for value in values:


# Count the number of values
count += 1

# Calculate the total


total += value

# Find the maximum value


if value > max_value:
max_value = value

# Find the minimum value


if value < min_value:
min_value = value

# Calculate the average value


average = total / count

print("Number of values:", count)


print("Maximum value:", max_value)
print("Minimum value:", min_value)
print("Average value:", average)

5
Page
8. DECLARE Months[12] AS STRING
DECLARE Rainfall[12][31] AS FLOAT
DECLARE AverageRainfall[12] AS FLOAT
DECLARE TotalRainfall AS FLOAT
DECLARE OverallAverageRainfall AS FLOAT

DEFINE Months[] = ["January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"]

LOOP i FROM 0 TO 11
OUTPUT "Enter daily rainfall for the month of " + Months[i]
LOOP j FROM 0 TO 30
INPUT Rainfall[i][j]
AverageRainfall[i] = AverageRainfall[i] + Rainfall[i][j]
END LOOP
AverageRainfall[i] = AverageRainfall[i] / 31
TotalRainfall = TotalRainfall + AverageRainfall[i]
END LOOP

OverallAverageRainfall = TotalRainfall / 12

OUTPUT "Average rainfall for each month:"


LOOP i FROM 0 TO 11
OUTPUT Months[i] + ": " + ROUND(AverageRainfall[i], 1)
END LOOP

OUTPUT "Overall average rainfall for the year: " + ROUND(OverallAverageRainfall, 1)

============= Python Codes ================

Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"]
Rainfall = [[0 for j in range(31)] for i in range(12)]
AverageRainfall = [0 for i in range(12)]
TotalRainfall = 0
OverallAverageRainfall = 0

for i in range(12):
print("Enter daily rainfall for the month of ", Months[i])
for j in range(31):
Rainfall[i][j] = float(input())
AverageRainfall[i] += Rainfall[i][j]
AverageRainfall[i] /= 31
TotalRainfall += AverageRainfall[i]

OverallAverageRainfall = TotalRainfall / 12

print("Average rainfall for each month:")


for i in range(12):
6

print(Months[i] + ": ", round(AverageRainfall[i], 1))


Page

print("Overall average rainfall for the year: ", round(OverallAverageRainfall, 1))

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy