[go: up one dir, main page]

0% found this document useful (0 votes)
6 views3 pages

PROGRAMMING FOR BUSINESS 2

The document provides Python programming exercises focused on business applications, including reversing a number to check for palindromes, calculating average, highest, and lowest scores, and determining a check digit for a four-digit number. It also covers calculating salesperson earnings based on sales, generating Fibonacci series using both for and while loops, and computing factorials with both loop types. Additionally, it discusses the efficiency of using while loops versus for loops in certain scenarios.

Uploaded by

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

PROGRAMMING FOR BUSINESS 2

The document provides Python programming exercises focused on business applications, including reversing a number to check for palindromes, calculating average, highest, and lowest scores, and determining a check digit for a four-digit number. It also covers calculating salesperson earnings based on sales, generating Fibonacci series using both for and while loops, and computing factorials with both loop types. Additionally, it discusses the efficiency of using while loops versus for loops in certain scenarios.

Uploaded by

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

PROGRAMMING FOR BUSINESS

(24K-7300)

Question 1: Reverse of a number and check if it's equal

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

reverse_num = int(str(num)[::-1])

if num == reverse_num:

print(f"{num} and its reverse {reverse_num} are equal (Palindrome).")

else:

print(f"{num} and its reverse {reverse_num} are not equal.")

Question 2: Average, highest, and lowest scores

scores = []

while True:

score = float(input("Enter a score (-1 to stop): "))

if score == -1:

break

scores.append(score)

if scores:

avg_score = sum(scores) / len(scores)

print(f"Average score: {avg_score}")

print(f"Highest score: {max(scores)}")

print(f"Lowest score: {min(scores)}")

else:

print("No scores entered.")

Question 3: Check digit calculation

number = input("Enter a four-digit number: ")

sum_digits = sum(int(digit) for digit in number)


check_digit = 0 if sum_digits % 2 == 0 else 1

new_number = number + str(check_digit)

print(f"Original number: {number}")

print(f"New number with check digit: {new_number}")

Question 4: Salesperson earnings calculation

while True:

sales = float(input("Enter sales in dollars (-1 to end): "))

if sales == -1:

break

salary = 200 + (0.09 * sales)

print(f"Salary is: ${salary:.2f}")

Question 5: Fibonacci series and sum

# Using for loop

fib_series = [1, 1]

for i in range(2, 1000):

next_num = fib_series[-1] + fib_series[-2]

if next_num > 1000:

break

fib_series.append(next_num)

print("Fibonacci series (for loop):", fib_series)

print("Sum of Fibonacci series (for loop):", sum(fib_series))

# Using while loop

fib_series_while = [1, 1]

while True:

next_num = fib_series_while[-1] + fib_series_while[-2]


if next_num > 1000:

break

fib_series_while.append(next_num)

print("Fibonacci series (while loop):", fib_series_while)

print("Sum of Fibonacci series (while loop):", sum(fib_series_while))

# Efficiency: While loop may have slightly better performance due to fewer range calculations.

Question 6: Factorial calculation

# Using for loop

num = int(input("Enter a number for factorial: "))

factorial = 1

for i in range(1, num + 1):

factorial *= i

print(f"Factorial of {num} (for loop): {factorial}")

# Using while loop

factorial_while = 1

counter = num

while counter > 0:

factorial_while *= counter

counter -= 1

print(f"Factorial of {num} (while loop): {factorial_while}")

# Efficiency: For loop is generally more readable and concise for factorial calculations.

You might also like