V

@Videonerd03

CSV FILE CORRECT FORMAT TO PRACTICE

Python
1 month ago
#import csv module and call open(), reader() #solution accepts input identifying name of CSV file ("input1.csv") #solution outputs each row of CSV file contents as a dictionary of elements import csv #accept string input identifying filename print("Enter the name of the file along with its extension:") file_name = input() #open, read, and output the new file contents in the reverse order

Parsing Food file

Python
1 month ago
#Given a text file containing the availability of food items, #write a program that reads the information from the text file and #outputs the available food items. #The program first reads the name of the text file from the user. #The program then reads the text file, stores the information into four separate lists, #and outputs the available food items in the following format: #name (category) -- description #Assume the text file contains #the category, name, description,

counting characters

Python
1 month ago
user_text = input() """ Type your code here. """ count = 0 for char in user_text: if char not in [' ', '.', '!', ',']: count += 1

Pig age converter

Python
1 month ago
import pigAge print("Enter the age of the pig in years:") pig_years= int(input()) human_years = pigAge.pigAge_converter(pig_years) print(f"{pig_years} pig years is equivalent to {human_years} in human years")

comparing values factorial method

Python
1 month ago
#solution accepts integer input and integer comparison value #solution outputs the factorial of the integer input #solution outputs Boolean identification of whether the factorial is greater than identified comparison value #import math module and call factorial() import math print("Enter a number to calculate its factorial:") factorial_value = int(input()) print("Enter a number to compare with the factorial:")

Reading a file list, and outputting in reverse

Python
1 month ago
import csv print("Enter the name of the file along with its extension:") filename = input() with open(filename, 'r', newline='') as file: reader = csv.reader(file) for row in reader: print(row[::-1])

Read and write files and combine three words into one sentence

Python
1 month ago
#solution accepts file input to insert sentence composed of file content into text file on a new line #solution outputs the text file contents including the new sentence #accept input identifying filename print("Enter the name of the input file:") file_name = input() #open, read, and write text file (e.g., "WordTextFile.txt") using open(), read(), write() with open(file_name, 'r') as file: lines = file.read().splitlines() #combine the three words into one sentence

Grocery item purchase

Python
1 month ago
#Create a solution that accepts a string input representing a #grocery store item and an integer input identifying the number of items purchased on a recent visit. #The following dictionary purchase lists available items as the key and the cost per item as the value. #purchase = {"bananas": 1.85, "steak": 19.99, "cookies": 4.52, "celery": 2.81, "milk": 4.34} #Additionally, #If fewer than 10 items are purchased, the price is the full cost per item. #If between 10 and 20 items (inclusive) ar

While loop for num_of_stocks

Python
1 month ago
#Create a solution that accepts #an integer input identifying how many different shares #of stock are purchased from the Old Town Stock Exchange, followed by an equivalent number of string inputs representing the stock selections. #The following dictionary, stock, lists available stock selections as the key and the cost per selection as the value. stocks = {'TSLA': 912.86 , 'BBBY': 24.84, 'AAPL': 174.26, 'SOFI': 6.92, 'KIRK': 8.72, 'AURA': 22.12, 'AMZN': 141.28, 'EMBK': 12.29, 'LVLU': 2.33}

Tempature

Python
1 month ago
# integer accepted representing the water tempature in degrees fahrenheit print("Enter the water temperature:") watertemp = int(input()) if watertemp <= 33: print("Frozen") elif 33 <= watertemp <= 80: print("Cold")

try except with index Practice #7

Python
1 month ago
#Create a solution that accepts one integer input representing the index value for any of the string elements in the following list: #frameworks = ["Django", "Flask", "CherryPy", "Bottle", "Web2Py", "TurboGears"] Output the string element of the index value entered. #Place the solution in a try block and implement an exception of "Error" #if an incompatible integer input is provided. frameworks = ["Django", "Flask", "CherryPy", "Bottle", "Web2Py", "TurboGears"]

Random number

Python
1 month ago
import random def number_guess(guess): rand_num = random.randint(1, 100) if guess < rand_num: print(f"{guess} is too low. Random number was {rand_num}.") elif guess > rand_num: print(f"{guess} is too high. Random number was {rand_num}.") else:

Python Practice Test # 3 Index

Python
1 month ago
#list of mixed data elements data_mixture = ["Python is fun", 2024, 5.67, ["apple", "banana", "coconut"], None, {"name": "John", "age": 25}] print("Enter index:") index = int(input()) element = data_mixture[index] if isinstance(element,(str, list, dict)): message = "This element is iterable"

Python Practice Test #2

Python
1 month ago
#there are 16 ounces in a pound and 2000 pounds in a ton #solution accepts an integer value representing any number of ounces #solution outputs the converted tons, pounds, and ounces represented by the input value of ounces print(f"Enter the number of ounces to convert:") ounces = int(input()) #convert ounces to pounds and tons ounces_per_pound = 16 pounds_per_ton = 2000

Python Practice Test #1

MySQL
1 month ago
#Employee A: 15.62 miles #Employee B: 41.85 miles #Employee C: 32.67 miles #solution accepts three integer inputs representing the number of times an employee travels to the job site #solution outputs "Distance: " followed by the total value to two decimal places #accept three integer inputs print("Enter the number of days Employee A travels to job:") Employee_a = int(input()) print("Enter the number of days Employee B travels to job:")

fat burning heart rate

MySQL
1 month ago
def get_age(): age = int(input()) if age < 18 or age > 75: raise ValueError("Invalid age.") return age def fat_burning_heart_rate(age): heart_rate = 0.70 * (220 - age) return heart_rate

File name change

Python
1 month ago
# Type your code here. filename = input().strip() with open(filename, 'r') as file: for line in file: photo_name = line.strip() info_name = photo_name.replace('_photo.jpg', '_info.txt') print(info_name)

Course Grade

Python
1 month ago
filename = input().strip() students = [] midterm1_scores = [] midterm2_scores = [] final_scores = [] # Read student data with open(filename, 'r') as file: for line in file:

Dictionaries and list

Python
1 month ago
# Read input file name filename = input().strip() # Read file contents using readlines() with open(filename, 'r') as file: lines = file.readlines() # Dictionary: seasons -> list of TV shows tv_dict = {}

File format

Python
1 month ago
# Type your code here. file_name = input().strip() lower = input().strip() upper = input().strip() file = open(file_name, 'r') words = file.readlines() file.close()