WGU D335 INTRODUCTION TO
PROGRAMMING IN PYTHON -
PERFORMANCE ASSESSMENT (PA)
100 CODING PRACTICE
QUESTIONS WITH VERIFIED
SOLUTIONS
SECTION ONE: QUESTIONS 1–100
Question 1
Problem: Write a program that takes an integer input from the user and
prints "Even" if the number is even, and "Odd" if the number is odd.
Solution:
python
num = int(input())
if num % 2 == 0:
print("Even")
else:
print("Odd")
RATIONALE: The modulus operator % returns the remainder. If num
% 2 == 0, the number is evenly divisible by 2, making it even.
,Question 2
Problem: Write a program that takes two integer inputs and prints their
sum, difference, product, and quotient (as a float).
Solution:
python
a = int(input())
b = int(input())
print("Sum:", a + b)
print("Difference:", a - b)
print("Product:", a * b)
print("Quotient:", a / b)
RATIONALE: Basic arithmetic operations are performed in Python.
Division / always returns a float. Output formatting must match exactly
as shown.
Question 3
Problem: Write a program that takes a string input and prints it in
reverse order.
Solution:
python
text = input()
print(text[::-1])
RATIONALE: The slice [::-1] starts at the end and moves backwards
with a step of -1, effectively reversing the string.
,Question 4
Problem: Write a program that takes a list of three integers and prints
the largest number.
Solution:
python
a = int(input())
b = int(input())
c = int(input())
largest = max(a, b, c)
print("Largest:", largest)
RATIONALE: The built-in max() function returns the highest value
among its arguments.
Question 5
Problem: Write a program that takes a temperature in Celsius and
converts it to Fahrenheit. Formula: F = (C * 9/5) + 32. Output to one
decimal place.
Solution:
python
celsius = float(input())
fahrenheit = (celsius * 9/5) + 32
print("Fahrenheit: {:.1f}".format(fahrenheit))
RATIONALE: The conversion formula is applied. .1f formats the
output to one decimal place.
, Question 6
Problem: Write a program that takes a string input and counts the
number of vowels (a, e, i, o, u) in it.
Solution:
python
text = input().lower()
vowels = "aeiou"
count = 0
for char in text:
if char in vowels:
count += 1
print("Vowels:", count)
RATIONALE: The string is converted to lowercase to handle
uppercase inputs. Each character is checked against the vowel set.
Question 7
Problem: Write a program that takes an integer n and prints all
numbers from 1 to n on a single line, separated by spaces.
Solution:
python
n = int(input())
for i in range(1, n + 1):
print(i, end=" ")
RATIONALE: range(1, n+1) generates numbers from 1 to n
inclusive. end=" " keeps output on one line with spaces.
PROGRAMMING IN PYTHON -
PERFORMANCE ASSESSMENT (PA)
100 CODING PRACTICE
QUESTIONS WITH VERIFIED
SOLUTIONS
SECTION ONE: QUESTIONS 1–100
Question 1
Problem: Write a program that takes an integer input from the user and
prints "Even" if the number is even, and "Odd" if the number is odd.
Solution:
python
num = int(input())
if num % 2 == 0:
print("Even")
else:
print("Odd")
RATIONALE: The modulus operator % returns the remainder. If num
% 2 == 0, the number is evenly divisible by 2, making it even.
,Question 2
Problem: Write a program that takes two integer inputs and prints their
sum, difference, product, and quotient (as a float).
Solution:
python
a = int(input())
b = int(input())
print("Sum:", a + b)
print("Difference:", a - b)
print("Product:", a * b)
print("Quotient:", a / b)
RATIONALE: Basic arithmetic operations are performed in Python.
Division / always returns a float. Output formatting must match exactly
as shown.
Question 3
Problem: Write a program that takes a string input and prints it in
reverse order.
Solution:
python
text = input()
print(text[::-1])
RATIONALE: The slice [::-1] starts at the end and moves backwards
with a step of -1, effectively reversing the string.
,Question 4
Problem: Write a program that takes a list of three integers and prints
the largest number.
Solution:
python
a = int(input())
b = int(input())
c = int(input())
largest = max(a, b, c)
print("Largest:", largest)
RATIONALE: The built-in max() function returns the highest value
among its arguments.
Question 5
Problem: Write a program that takes a temperature in Celsius and
converts it to Fahrenheit. Formula: F = (C * 9/5) + 32. Output to one
decimal place.
Solution:
python
celsius = float(input())
fahrenheit = (celsius * 9/5) + 32
print("Fahrenheit: {:.1f}".format(fahrenheit))
RATIONALE: The conversion formula is applied. .1f formats the
output to one decimal place.
, Question 6
Problem: Write a program that takes a string input and counts the
number of vowels (a, e, i, o, u) in it.
Solution:
python
text = input().lower()
vowels = "aeiou"
count = 0
for char in text:
if char in vowels:
count += 1
print("Vowels:", count)
RATIONALE: The string is converted to lowercase to handle
uppercase inputs. Each character is checked against the vowel set.
Question 7
Problem: Write a program that takes an integer n and prints all
numbers from 1 to n on a single line, separated by spaces.
Solution:
python
n = int(input())
for i in range(1, n + 1):
print(i, end=" ")
RATIONALE: range(1, n+1) generates numbers from 1 to n
inclusive. end=" " keeps output on one line with spaces.