Kevin Tiller

All generations.

code to explanationThu, 20 Apr 2023

if __name__ == '__main__': score = 0 current_round = 0 question_list = read_file() while score < 5: current_round = next_round(current_round) question_list = ask_questions(question_list) score = 5 - len(question_list)if __name__ == '__main__': score = 0 current_round = 0 question_list = read_file() while score < 5: current_round = next_round(current_round) question_list = ask_questions(question_list) score = 5 - len(question_list)

The question is asked and the while loop will loop through the questions until the score is 5.

generate functionSat, 22 Apr 2023

Write a function that converts an int num between 0-9 (inclusive) to its string equivalent (i.e., 1 -> "one").

def convert(number): if number == 0: return "zero" if number == 1: return "one" if number == 2: return "two" if number == 3: return "three" if number == 4: return "four" if number == 5: return "five" if number == 6: return "six" if number == 7: return "seven" if number == 8: return "eight" if number == 9: return "nine" convert(0) convert(1) convert(2) convert(3) convert(4) convert(5) convert(6) convert(7) convert(8) convert(9)

Python
View
fix invalid codeThu, 20 Apr 2023

def read_file(): with open('questions.txt') as f: lines = f.readlines() question_list = [] for line in lines: question, answer = line.strip().split('=') question_list.append((question, answer)) return question_list import random print(random.random("questions.text"))

def read_file(): with open('questions.txt') as f: lines = f.readlines() question_list = [] for line in lines: question, answer = line.strip().split('=') question_list.append((question, answer)) return question_list import random print(random.random("questions.text"))

fix invalid codeFri, 21 Apr 2023

def read_file(): with open('questions.txt') as f: lines = f.readlines() question_list = [] for line in lines: question, answer = line.strip().split('=') question_list.append((question, answer)) return question_list import random print(random.random("questions.text"))

## Part 7: Tests ### Test 1: - Test that a user gets asked a question ### Test 2: - Test that a user gets asked a question and can answer a question ### Test 3: - Test that a user gets asked a question, can answer a question and gets a new question after answering a question ### Test 4: - Test that a user gets asked a question, can answer a question and gets a new question after answering a question, and the number of questions answered is tracked ### Test 5: - Test that a user gets asked a question, can answer a question and gets a new question after answering a question, and the number of questions answered is tracked, and the score is tracked ### Test 6: - Test that a user gets asked a question, can answer a question and gets a new question after answering a question, and the number of questions answered is tracked, and the score is tracked and the game ends after 5 questions ### Test 7: - Test that a user gets asked a question, can answer a question and gets a new question after answering a question,

fix invalid codeThu, 20 Apr 2023

def ask_questions(list_of_questions): import random order = list(range(len(questions))) random.shuffle(order) end_test = False num_questions = len(q) score = 0 while not end_test: num_skipped = []

There's also a notebook that explains some of the techniques used to generate the data as well as some experiments we ran to improve it. ## Data In the data folder, you can find the raw data and the generated data (`raw.json` and `data.json` respectively). The raw data is the data we got from the parser, that is, the code, the errors and the corrections. The generated data is the same data, but transformed into a format that's easier to work with when training models. The format of the generated data is like this:

fix invalid codeThu, 11 May 2023

if operation[1] == '+' else int(operation[0]) - int(operation[2])

## References & Resources - [Regular Expressions](https://docs.python.org/3/library/re.html) - [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) - [requests](https://requests.readthedocs.io/en/master/) - [sphinx](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/intro.html) - [pytest](https://docs.pytest.org/en/latest/) ## Contributing When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. Please note we have a [code of conduct](./CODE_OF_CONDUCT.md). Please follow it in all your interactions with the project. ### Issue/Bug Request **If you are having an issue with the existing project code, please submit a bug report under the following guidelines:** -

code to explanationThu, 01 Jun 2023

import json data = ''' [ { "id" : "001", "x" : "2", "name" : "Quincy" } , { "id" : "009", "x" : "7", "name" : "Mrugesh" } ] ''' info = json.loads(data) print(info[1]['name'])

The code block above imports the json module and uses json.loads() to process the data. The json.loads() function converts a string that contains json data into a list. In this case, it converts the string data into a list of 2 dictionaries. To access the information we need, we access the list using info[1], since info is the name of the list, and then access the second dictionary in the list using the ["name"] key.

fix invalid codeThu, 20 Apr 2023

def read_file(): with open('questions.txt') as f: lines = f.readlines() return question_list import random print(random.random("questions.text"))

def read_file(): with open('questions.txt') as f: lines = f.readlines() question_list = [] for line in lines: question, answer = line.strip().split('=') question_list.append((question, answer)) return question_list import random question_list = read_file() question = random.choice(question_list) while True: answer = input(question[0]) if answer == question[1]: print('Correct') break else: print('Wrong, try again')

generate functionThu, 20 Apr 2023

A program that administers and grades a multiple-choice exam. It starts off with 5 questions and repeats the questions that were incorrectly answered until all questions have been correctly answered.

def quiz(): questions = ['1. What color is the sky?\na. Blue\nb. Red\nc. Green\n', '2. What color is the sun?\na. Blue\nb. Red\nc. Yellow\n', '3. What color is an apple?\na. Blue\nb. Red\nc. Green\n', '4. What color is a banana?\na. Blue\nb. Red\nc. Yellow\n', '5. What color is the grass?\na. Blue\nb. Red\nc. Green\n'] answers = ['a', 'c', 'b', 'c', 'c'] print("Welcome to the quiz.") score = 0 total = len(questions) n = 0 while n < len(questions): print(questions[n]) ans = input('Enter your answer: ') if ans == answers[n]: print("Correct!\n") score +=

Python
View
fix invalid codeThu, 11 May 2023

def arithmetic_arranger(problem, *args): if len(problems) > 5: return("Error: Too Many Problems") arranged_problems:"" for index, value in emumerate(problem): operation = vaule.splt(" ") if operation[1] not in "-+": return"Error: operator must be '+' or '-'." if len(operation[0]) >4 or len(operation[2]) > 4: return "len(operation[0]) > 4" try: value_1 = int(operation[0]) value_2 = int(operation[2]) except ValueError: return"Error values must only contain digits" longest_val = max(len(operation[0]), len(operation[2])) width = longest_val + 2 L1 = f"{operation[0] :>{width}}" L2 = operation[1] + f"{operation[0] :>{width}}" d = "-" * width try: arranged_problems[0] += (" " * 4) + L1 except IndexError: arranged_problems.append(L1) try: arranged_problems[1] += (" " * 4) + L2 except IndexError: arranged_problems.append(L2) try: arranged_problems[0] += (" " * 4) + d except IndexError: arranged_problems.append(d) if args: ans = int(operation[0]) + int(operation[2]) if operation[1] == '+' else int(operation[0]) - int(operation[2]) a = f"{ans :> {width}}" try: arranged_problems[3] += (" " * 4) + a except IndexError: arranged_problems.append(d) output = f"{arranged_problems[0]} \n {arranged_problems[1]} \n {arranged_problems[2]}" output = output + f"\n{arranged_problems[3]}" if args else output return output

## Running the tests To run the tests, run the appropriate command below ([why they are different](https://github.com/pytest-dev/pytest/issues/1629#issue-161422224)): - Python 2.7: `py.test arithmetic_arranger_test.py` - Python 3.4+: `pytest arithmetic_arranger_test.py` Alternatively, you can tell Python to run the pytest module (allowing the same command to be used regardless of Python version): `python -m pytest arithmetic_arranger_test.py` ### Common `pytest` options - `-v` : enable verbose output - `-x` : stop running tests on first failure - `--ff` : run failures from previous test before running other test cases For other options, see `python -m pytest -h` ## Submitting Exercises Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/arithmetic-arranger`

code to explanationThu, 20 Apr 2023

def ask_questions(list_of_questions): import random order = list(range(len(questions))) random.shuffle(order) end_test = False num_questions = len(q) score = 0 while not end_test: num_skipped = []

The code above is a function called ask_questions which takes one argument called list_of_questions. The function will ask the questions in a random order and ask the user if they want to skip a question. The user will be given a score out of the total number of questions

fix invalid codeSun, 23 Apr 2023

def max_of_three( x, y, z ): num1 = int(input("Please enter num1")) num2 = int(input("Please enter num2")) num3 = int(input("Please enter num3")) range(x, y, z) if x>y and x>c : print("Biggest Number=",a) elif y>x and y>z: print("Biggest Number=",b) elif x==y: print("x=y") elif a==c: print("x=z") elif b==c: print("y=z") else: print("The max of the three numbers is:",max_of_three(num1, num2, num3)) num1 = int(input("Please enter num1")) num2 = int(input("Please enter num2")) num3 = int(input("Please enter num3"))

def max_of_three( num1, num2, num3 ): if num1 > num2 and num1 > num3: print("Biggest Number=",num1) elif num2 > num1 and num2 > num3: print("Biggest Number=",num2) elif num1 == num2: print("num1=num2") elif num1 == num3: print("num1=num3") elif num2 == num3: print("num2=num3") else: print("The max of the three numbers is:",max_of_three(num1, num2, num3))

generate functionSat, 22 Apr 2023

Write a function that converts an int num between 0-9 (inclusive) to its string equivalent (i.e., 1 -> "one").

def convert(int_num): num_string = "" if int_num == 1: num_string = "one" elif int_num == 2: num_string = "two" elif int_num == 3: num_string = "three" elif int_num == 4: num_string = "four" elif int_num == 5: num_string = "five" elif int_num == 6: num_string = "six" elif int_num == 7: num_string = "seven" elif int_num == 8: num_string = "eight" elif int_num == 9: num_string = "nine" else: num_string = "zero" return num_string # test print(convert(1)) print(convert(3)) print(convert(9)) print(convert(10)) ``

Python
View
code to explanationThu, 20 Apr 2023

if __name__ == '__main__': score = 0 current_round = 0 question_list = read_file() while score < 5: current_round = next_round(current_round) question_list = ask_questions(question_list) score = 5 - len(question_list)if __name__ == '__main__': score = 0 current_round = 0 question_list = read_file() while score < 5: current_round = next_round(current_round) question_list = ask_questions(question_list) score = 5 - len(question_list)

This block has the code for the round

fix invalid codeThu, 20 Apr 2023

def read_file(): with open('questions.txt') as f: lines = f.readlines() return question_list import random print(random.random("questions.text")) def ask_questions(list_of_questions): import random order = list(range(len(questions))) random.shuffle(order) end_test = False num_questions = len(q) score = 0 while not end_test: num_skipped = [] def display_question(question_number, question): for i in range(num_questions): q_text = q[i][0] q_answer = q[i][1] choices = q[i][2:] print(q_text) print('A. ' + choices[0]) print('B. ' + choices[1]) print('C. ' + choices[2]) print('D. ' + choices[3]) user_answer = input("Please enter A, B, C or D: ").upper() def is_correct_answer(solution, user_answer): if user_answer == q_answer: score += 1 print("Correct!") else: num_skipped.append(q[i]) print("Incorrect. The correct answer is " + q_answer + ".") print("") def next_round(current_round):

def next_round(current_round): if current_round < num_questions: return current_round + 1 else: return 0

generate functionSun, 23 Apr 2023

The Fibonacci Sequence is a series of numbers. The next number is found by adding up the two numbers before it. For example, 0, 1, 1, 2, 3, 5, 8, 13, 21. The next number in this series is 13+21 = 34. Write a program that will take as user input any two consecutive numbers between 0 and 21 in the Fibonacci sequence, e.g. 1 1 or 8 13. The next number in the sequence should be stored in a variable called next. After that print next

def fibonacci(a, b): return a + b fibonacci(13, 21)

Python
View
fix invalid codeSun, 23 Apr 2023

def max_of_three( x, y, z ): num1 = int(input("Please enter num1")) num2 = int(input("Please enter num2")) num3 = int(input("Please enter num3")) range(x, y, z) if x>y and x>c : print("Biggest Number=",a) elif y>x and y>z: print("Biggest Number=",b) elif x==y: print("x=y") elif a==c: print("x=z") elif b==c: print("y=z") else: print("The max of the three numbers is:",max_of_three(num1, num2, num3)) num1 = int(input("Please enter num1")) num2 = int(input("Please enter num2")) num3 = int(input("Please enter num3"))

def max_of_three( x, y, z ): if x>y and x>c : print("Biggest Number=",a) elif y>x and y>z: print("Biggest Number=",b) elif x==y: print("x=y") elif a==c: print("x=z") elif b==c: print("y=z") else: print("The max of the three numbers is:",max_of_three(num1, num2, num3)) num1 = int(input("Please enter num1")) num2 = int(input("Please enter num2")) num3 = int(input("Please enter num3"))

fix invalid codeSat, 22 Apr 2023

def int_to_string(num): if num == 0: return 'zero' elif num == 1: return 'one' elif num == 2: return 'two' elif num == 3: return 'three' elif num == 4: return 'four' elif num == 5: return 'five' elif num == 6: return 'six' elif num == 7: return 'seven' elif num == 8: return 'eight' elif num == 9: return 'nine' else: return 'not a valid number' num = int(input()) print(int_to_string(num))

def int_to_string(num): if num == 0: return 'zero' elif num == 1: return 'one' elif num == 2: return 'two' elif num == 3: return 'three' elif num == 4: return 'four' elif num == 5: return 'five' elif num == 6: return 'six' elif num == 7: return 'seven' elif num == 8: return 'eight' elif num == 9: return 'nine' else: return 'not a valid number' num = int(input()) print(int_to_string(num))

generate functionSat, 22 Apr 2023

Write a function that converts an int num between 0-9 (inclusive) to its string equivalent (i.e., 1 -> "one").

def intToString(num): if num == 0: return 'zero' elif num == 1: return 'one' elif num == 2: return 'two' elif num == 3: return 'three' elif num == 4: return 'four' elif num == 5: return 'five' elif num == 6: return 'six' elif num == 7: return 'seven' elif num == 8: return 'eight' elif num == 9: return 'nine' else: return 'not a valid number' intToString(9)

Python
View
generate functionThu, 20 Apr 2023

A program that administers and grades a multiple-choice exam. It starts off with 5 questions and repeats the questions that were incorrectly answered until all questions have been correctly answered.

def multiplechoice(): question = 0 correct = 0 while question < 5: if question == 0: answer = input("What is the capital of New York?") if answer == "Albany": correct += 1 else: question -= 1 elif question == 1: answer = input("What is the capital of California?") if answer == "Sacramento": correct += 1 else: question -= 1 elif question == 2: answer = input("What is the capital of New Jersey?") if answer == "Trenton": correct += 1 else: question -= 1 elif question == 3: answer = input("What is the capital of Florida?") if answer == "Tallahassee": correct += 1 else: question -= 1 elif question == 4: answer = input("What is the capital of Washington

Python
View
code to explanationSat, 22 Apr 2023

words = 'His e-mail is q-lar@freecodecamp.org' pieces = words.split() parts = pieces[3].split('-') n = parts[1]

The function words.split() splits the string words into a list of four strings: 'His', 'e-mail', 'is' and 'q-lar@freecodecamp.org'. The function parts.split('-') splits the string 'q-lar@freecodecamp.org' into a list of two strings: 'q' and 'lar@freecodecamp.org'. The variable n is assigned the second string in the list parts, i.e., 'lar@freecodecamp.org'.

code to explanationThu, 01 Jun 2023

def add_time(start, duration): [L, N] = start.split(" ") [SH, SM] = L.split(":") [DH, DM] = duration.split(":") new_time = str(int(SH)) + int(DH) + ":" new_time = str(int(SM)) + int(DM) + f"{N}" return new_time print(add_time("3:00 PM", "3:10"))

The function add_time takes two arguments start and duration that represent the starting time of a movie and its duration. The function then uses the split method to take the start argument and split it into two parts, first the time and second the am or pm part. The function then uses the split method again to take the time part and split it into hours and minutes. The function then uses a third split method to take the duration argument and split it into hours and minutes. The function then takes the hours of the start time and the duration and adds them together to get a new hours integers. The function then takes the minutes of the start time and duration and adds them together to get a new minutes integers. The function then adds the new hours and minutes together to get a new time string. The function then adds the am or pm part to the new time string. The function then returns the new time string. When the function is called in the last line, the string "3:00 PM" is passed to the start argument and the string "3:10" is passed to the

Want to kickstart your project?Use the new AI Studio to create your code