Docsity

WGU D335 Intro to Python OA.pdf, Exams of Introduction to biology

Partial preview of the text

Download WGU D335 Intro to Python OA.pdf and more Exams Introduction to biology in PDF only on Docsity!

WGU D335 Intro to Python OA – Ultimate

Objective Assessment Study Guide with

Complete Q&A (Latest Edition)

Question 1 Create a solution that accepts an integer input representing any number of ounces. Output the converted total number of tons, pounds, and remaining ounces based on the input ounces value. There are 16 ounces in a pound and 2,000 pounds in a ton. The output should be in the format: Tons: value_ Pounds: value_ Ounces: value_

ANSWER ⇒⇔

python ounces = int(input()) value_1 = ounces // (16 * 2000) value_2 = (ounces % (

  • 2000)) // 16 value_3 = ounces % 16 print(f"Tons: {value_1}")

print(f"Pounds: {value_2}") print(f"Ounces: {value_3}") Question 2 Create a solution that accepts an integer input representing the index value for any of the five elements in the following list: various_data_types = [516, 112.49, True, "meow", ("Western", "Governors", "University"), {"apple": 1, "pear": 5}] Using the built-in function type() and getting its name by using the .name attribute, output the data type (e.g., "int", "float", "bool", "str") based on the input index value. Output format: Element index_value: data_type

ANSWER ⇒⇔

python various_data_types = [516, 112.49, True, "meow", ("Western", "Governors", "University"), {"apple": 1, "pear": 5}] index_value = int(input()) data_type = type(various_data_types[index_value]).name print(f"Element {index_value}: {data_type}") Question 3 Create a solution that accepts any three integer inputs representing the base (b1, b2) and height (h) measurements of a trapezoid in meters. Output the exact area of the trapezoid in square meters as a float value. The area formula is: A = ((b1 + b2) / 2) * h Output format:

int(input()) num5 = int(input()) integer_sum = num1 + num2 + num3 + num4 + num float_sum = float(num1) + float(num2) + float(num3) + float(num4) + float(num5) string_sum = str(num1) + str(num2) + str(num3) + str(num4) + str(num5) print(f"Integer: {integer_sum}") print(f"Float: {float_sum}") print(f"String: {string_sum}") Question 5 Create a solution that accepts a string input representing a grocery item. Output the item in uppercase and lowercase, and also output the length of the string. Output format: Uppercase: item_upper Lowercase: item_lower Length: length_value

ANSWER ⇒⇔

python item = input() print(f"Uppercase: {item.upper()}") print(f"Lowercase: {item.lower()}") print(f"Length: {len(item)}")

Question 6 Create a solution that accepts two integer inputs representing a numerator and denominator. Output the result of integer division, the remainder, and the floating-point division. Output format: Integer division: quotient Remainder: remainder Float division: result

ANSWER ⇒⇔

python num = int(input()) den = int(input()) quotient = num // den remainder = num % den float_div = num / den print(f"Integer division: {quotient}") print(f"Remainder: {remainder}") print(f"Float division: {float_div}")

Question 9 Create a solution that accepts a string input. If the string is "red", output "Stop". If "yellow", output "Caution". If "green", output "Go". For any other input, output "Invalid".

ANSWER ⇒⇔

python color = input().strip() if color == "red": print("Stop") elif color == "yellow": print("Caution") elif color == "green": print("Go") else: print("Invalid") Question 10 Create a solution that accepts two integer inputs: start and end. Output all even numbers between start and end (inclusive) separated by spaces.

ANSWER ⇒⇔

python start = int(input()) end = int(input()) result = [] for num in range(start, end + 1): if num

result.append(str(num)) print(" ".join(result)) Question 11 Create a solution that accepts five integer inputs and stores them in a list. Output the list sorted in ascending order, then in descending order, each on a new line.

ANSWER ⇒⇔

python nums = [] for _ in range(5): nums.append(int(input())) nums.sort() print(nums) nums.sort(reverse=True) print(nums) Question 12 Create a solution that accepts a string input. Count the number of vowels (a, e, i, o, u) in the string (case-insensitive) and output the count.

ANSWER ⇒⇔

python text = input().lower() vowels = "aeiou"

0 int(input()) avg = (s

  • s2 + s3) / 3 print(f"{avg:.2f}") Question 15 Create a solution that accepts a string input and a character input. Output the index (0-based) of the first occurrence of the character in the string. If not found, output - 1.

ANSWER ⇒⇔

python text = input() ch = input() print(text.find(ch)) Question 16 Create a solution that accepts a list of five integers (each on a separate line). Output the maximum and minimum values.

ANSWER ⇒⇔

python nums = [int(input()) for _ in range(5)] print(f"Max: {max(nums)}") print(f"Min: {min(nums)}")

1 Question 17 Create a solution that accepts a string input. Output the string reversed.

ANSWER ⇒⇔

python text = input() print(text[::-1]) Question 18 Create a solution that accepts an integer input n. Output the multiplication table for n from 1 to 10, each line as: n x i = result.

ANSWER ⇒⇔

python n = int(input()) for i in range(1, 11): print(f"{n} x {i} = {n * i}") Question 19 Create a solution that accepts a list of five names (strings) and a search name. Output "Found" if the name exists in the list, otherwise "Not found".

ANSWER ⇒⇔

python names = [input() for _ in range(5)] search = input() if search in names: print("Found") else:

3 result *= base print(result) Question 22 Create a solution that accepts a string input. Output the string with all spaces replaced by underscores.

ANSWER ⇒⇔

python text = input() print(text.replace(" ", "_")) Question 23 Create a solution that accepts three integer inputs: a, b, c. Determine if they can form a Pythagorean triple (a² + b² = c²). Output "Yes" or "No".

ANSWER ⇒⇔

python a = int(input()) b = int(input()) c = int(input()) if a2 + b2 == c**2: print("Yes") else: print("No")

4 Question 24 Create a solution that accepts a string input. Output the number of words in the string (words separated by spaces).

ANSWER ⇒⇔

python text = input() words = text.split() print(len(words)) Question 25 Create a solution that accepts five integer inputs and stores them in a list. Output the sum of all elements using a loop (without using sum()).

ANSWER ⇒⇔

python nums = [int(input()) for _ in range(5)] total = 0 for num in nums: total += num print(total) Question 26 Create a solution that accepts a string input. Output True if the string is a palindrome (reads same forwards and backwards), otherwise False. Ignore case and spaces.

ANSWER ⇒⇔

python

6 Question 29 Create a solution that accepts an integer n. Output the Fibonacci sequence up to n terms (starting with 0, 1).

ANSWER ⇒⇔

python n = int(input()) a, b = 0, 1 for _ in range(n): print(a, end=" ") a, b = b, a + b Question 30 Create a solution that accepts two integer inputs: start and step. Use a while loop to print numbers starting from start, increasing by step, until the number exceeds

  1. Print each number on the same line separated by spaces.

ANSWER ⇒⇔

python start = int(input()) step = int(input()) current = start while current <= 100: print(current,

7 end=" ") current += step Question 31 Create a solution that accepts a string input. Output the string in title case (first letter of each word capitalized).

ANSWER ⇒⇔

python text = input() print(text.title()) Question 32 Create a solution that accepts a list of five integers. Output the list after doubling each element.

ANSWER ⇒⇔

python nums = [int(input()) for _ in range(5)] doubled = [x * 2 for x in nums] print(doubled) Question 33 Create a solution that accepts a string input. Output the string without any vowels.

ANSWER ⇒⇔

python

9 text = input() result = "" for ch in text: if ch.islower(): if ch == 'z': result += 'a' else: result += chr(ord(ch) + 1) else: result += ch print(result) Question 36 Create a solution that accepts an integer n. Output the factorial of n using a loop.

ANSWER ⇒⇔

python n = int(input()) fact = 1 for i in range(1, n + 1): fact *= i print(fact) Question 37 Create a solution that accepts a list of five integers. Output the list in reverse order.

0

ANSWER ⇒⇔

python nums = [int(input()) for _ in range(5)] print(nums[::-1]) Question 38 Create a solution that accepts a string input. Output the number of uppercase letters, lowercase letters, and digits in the string.

ANSWER ⇒⇔

python text = input() upper = lower = digit = 0 for ch in text: if ch.isupper(): upper += 1 elif ch.islower(): lower += 1 elif ch.isdigit(): digit += 1 print(f"Uppercase: {upper}, Lowercase: {lower}, Digits: {digit}") Question 39 Create a solution that accepts a list of five names. Output the names in alphabetical order.

ANSWER ⇒⇔

python