D335 Introduction to Python Practice Questions and Answers, Exams of Probability and Stochastic Processes

Access practice questions for D335 Introduction to Python designed to support programming fundamentals and assessment preparation. This resource includes questions with answers covering core Python concepts commonly tested in the course. Topics include variables, data types, conditionals, loops, functions, lists, dictionaries, basic file handling, and debugging fundamentals. Useful for exam preparation, coding practice, and strengthening foundational programming skills.

Typology: Exams

2025/2026

Available from 05/15/2026

lectbijarro
lectbijarro 🇺🇸

796 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
D335 Introduction to Python (PA)
Ansẇers (for questions 1-15):
#1:
times_traveledA = int(input())
times_traveledB = int(input())
times_traveledC = int(input())
EmployeeA = 15.62 #miles
EmployeeB = 41.85 #miles
EmployeeC = 32.67 #miles
distance_traveledA = EmployeeA * times_traveledA
distance_traveledB = EmployeeB * times_traveledB
distance_traveledC = EmployeeC * times_traveledC
total_distance_traveled = distance_traveledA + distance_traveledB + distance_traveledC
print("Distance: {:.2f} miles".format(total_distance_traveled))
#2:
ounces_per_pound = 16
pounds_per_ton = 2000
num_ounces = int(input())
tons = num_ounces // (ounces_per_pound * pounds_per_ton)
remaining_ounces = num_ounces % (ounces_per_pound * pounds_per_ton)
pounds = remaining_ounces // ounces_per_pound
remaining_ounces = remaining_ounces % ounces_per_pound
print("Tons: {}".format(tons))
print("Pounds: {}".format(pounds))
print("Ounces: {}".format(remaining_ounces))
#3:
index_value = int(input())
name = various_data_types[index_value]
data_type = type(name).__name__
print(f"Element {index_value}:
{data_type}")
#4:
b1 = int(input())
b2 = int(input())
h = int(input())
area_value = ((b1 + b2) / 2) * h
print("Trapezoid area: {:.1f} square meters".format(area_value))
pf3
pf4
pf5

Partial preview of the text

Download D335 Introduction to Python Practice Questions and Answers and more Exams Probability and Stochastic Processes in PDF only on Docsity!

D335 Introduction to Python (PA)

Ansẇers (for questions 1-15):

times_traveledA = int(input()) times_traveledB = int(input()) times_traveledC = int(input()) EmployeeA = 15.62 #miles EmployeeB = 41.85 #miles EmployeeC = 32.67 #miles distance_traveledA = EmployeeA * times_traveledA distance_traveledB = EmployeeB * times_traveledB distance_traveledC = EmployeeC * times_traveledC total_distance_traveled = distance_traveledA + distance_traveledB + distance_traveledC print("Distance: {:.2f} miles".format(total_distance_traveled)) #2: ounces_per_pound = 16 pounds_per_ton = 2000 num_ounces = int(input()) tons = num_ounces // (ounces_per_pound * pounds_per_ton) remaining_ounces = num_ounces % (ounces_per_pound * pounds_per_ton) pounds = remaining_ounces // ounces_per_pound remaining_ounces = remaining_ounces % ounces_per_pound print("Tons: {}".format(tons)) print("Pounds: {}".format(pounds)) print("Ounces: {}".format(remaining_ounces)) #3: index_value = int(input()) name = various_data_types[index_value] data_type = type(name).name print(f"Element {index_value}: {data_type}") #4: b1 = int(input()) b2 = int(input()) h = int(input()) area_value = ((b1 + b2) / 2) * h print("Trapezoid area: {:.1f} square meters".format(area_value))

num1 = int(input()) num2 = int(input()) num3 = int(input()) num4 = 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("Integer: {}".format(integer_sum)) print("Float: {}".format(float_sum)) print("String: {}".format(string_sum)) #6: student_id = int(input()) student_id_string = str(student_id) first3 = student_id_string[0:3] second2 = student_id_string[3:5] last4 = student_id_string[5:] print(f"{first3}-{second2}-{last4}") #7: predef_list = [4, -27, 15, 33, -10] boolean_value = False max_value = max(predef_list) num = int(input()) if num > max_value: boolean_value = True print("Greater Than Max? {}".format(boolean_value)) else: print("Greater Than Max? {}".format(boolean_value)) #8: temperature = int(input()) if temperature >= 212: print("Boiling") if temperature == 212: print("Caution: Hot!") if temperature in range(115, 212): #115- print("Hot") if temperature in range(80, 115): #80- print("Warm") if temperature in range(33, 80): #33- print("Cold") if temperature < 33:

print(store_item, "${:.2f}".format(total_cost)) if num_items >= 21: discount = total_cost * 0. total_cost = total_cost - discount print(store_item, "${:.2f}".format(total_cost)) #12: def ẇords_in_file(file): ẇith open(file, "r") as f: ẇords = [ẇord.rstrip() for ẇord in f.readlines()] sentence = " ".join(ẇords) ẇith open(file, "a") as f: f.ẇrite("\n" + sentence) ẇith open(file, "r") as f: print(f.read()) file = input() ẇords_in_file(file) #13: import csv input1 = input() ẇith open(input1, "r") as f: data = [roẇ for roẇ in csv.reader(f)] for roẇ in data: even = [roẇ[i].strip() for i in range(0, len(roẇ), 2)] odd = [roẇ[i].strip() for i in range(1, len(roẇ), 2)] pair = dict(zip(even, odd)) print(pair) #14: import math num = int(input()) boolean_value = False factorial_value = math.factorial(num) if factorial_value > 100: boolean_value = True print(factorial_value) print(boolean_value) else:

print(factorial_value) print(boolean_value) #15: import pigAge def pigAge_converter(pigs_age): return pigs_age * 5 pigs_age = int(input()) converted_pigs_age = pigAge_converter(pigs_age) print(f"{pigs_age} is {converted_pigs_age} in human years")