text
stringlengths
41
3.71k
ntok
int64
40
1.02k
style
stringclasses
3 values
name
stringlengths
1
252
hash
stringlengths
24
24
model
stringclasses
2 values
# by Kami Bigdely # Pull up constructor body class Pizza: "Pizza" order_num = 0 def __init__(self, toppings): self.toppings = toppings @staticmethod def validate_topping(topping): if topping == "pineapple": raise ValueError("No pineapples!") else: r...
248
mix
replace_whitespace.py
b536961f7a9c61f4650a2f8d
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(value: str) -> str: """Replace whitespace characters in a string with the single character '.'.""" return ''.join(['.' if char.isspace() else char for char in value])
65
mix
replace_whitespace.py
a263cedb1b8a3cdc0178d368
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(s: str, replacement: str) -> str: """Replace all whitespace characters in a string with a specified character or string. """ return s.replace(' ', replacement)
67
mix
replace_whitespace.py
4a50fd6489ff2d47d7ef7f9b
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(s: str, replacement: str) -> str: """Replace all whitespace characters in a string with a specified replacement string. """ return ' '.join(s.split())
62
mix
replace_whitespace.py
1ace74b43531b76bf94bc3ca
Qwen/Qwen2.5-Coder-7B
import re def replace_whitespace(string: str) -> str: """ Using re.sub, replace all whitespace characters with an underscore. """ return re.sub(r"\s+", "_", string)
65
mix
replace_whitespace.py
16841396fabb13cf685eb1d4
Qwen/Qwen2.5-Coder-7B
def remove_whitespace(s: str) -> str: """Remove whitespace (spaces, tabs, newlines) from the given string.""" result = "" for char in s: if char.strip(): result += char return result
66
mix
replace_whitespace.py
b1a681e2a0e84d20e7694615
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(filename: str) -> str: """Remove all whitespace characters from the first line of a file and write the modified line back to the same file. Parameters ---------- filename : str The name of the file to be modified. Returns ------- str The modified ...
183
mix
replace_whitespace.py
faf7727eebb65e6d8428b356
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(s: str) -> str: """Replace whitespace characters in a string with underscores.""" result = "" for char in s: if char.isspace(): result += "_" else: result += char return result
72
mix
replace_whitespace.py
dc25249ec6b9369e0ed4bab9
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(sentence: str) -> str: """Replace any whitespace character in a string with a single space.""" result: str = "" for char in sentence: if char.isspace(): char = ' ' result += char return result
80
mix
replace_whitespace.py
d4de1f1a658a0f3fe918b574
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(s: str) -> str: """Replace whitespace with underscores to format a string.""" return s.replace(" ", "_")
46
mix
replace_whitespace.py
4a49b233cc9dd54b2147dc0f
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(sentence: str) -> str: """Replace whitespace between words with an underscore.""" new_sentence = "" for char in sentence: if char == " ": new_sentence += "_" else: new_sentence += char return new_sentence
91
mix
replace_whitespace.py
d3ea8d3f9ddfd5fc639439ab
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(s: str) -> str: """Replace multiple consecutive whitespace characters with a single space in a string. """ return " ".join(s.split())
61
mix
replace_whitespace.py
d0912cf02c789532cfd00d76
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(s: str) -> str: """Replace sequences of whitespace with underscores in a string.""" result = "" for char in s: if char.isspace(): result += "_" else: result += char return result
73
mix
replace_whitespace.py
9333cd85c58848d28375eaf7
Qwen/Qwen2.5-Coder-7B
# Replace With Whitespace def normalize_height(heights_in_m: str) -> int: """Normalize the input height by replacing commas with periods and returning the value as an integer. """ result = heights_in_m.replace(",", ".") return int(float(result)) def parse_heights(some_input_heights: str) -> list[int]:...
259
mix
replace_whitespace.py
82d5ad55f88f1fc2eb5bcebc
Qwen/Qwen2.5-Coder-7B
def replace_whitespace(input_string: str) -> str: """Replace all whitespace characters with underscores in the input string.""" return '_'.join(input_string.split())
50
mix
replace_whitespace.py
6b330ec30b502dd49f2ea16a
Qwen/Qwen2.5-Coder-7B
# Python 3.7 balance = float(input("How much would you like to loan?: $")) interest_rate = float(input("What is the interest rate?: ")) minimum_payment = float(input("What is the minimum payment?: ")) while balance > 0: balance = balance - minimum_payment interest = balance * (interest_rate / 100) balance =...
211
pe
1.03.py
65033b00eaacaaa59278e17d
Qwen/Qwen2.5-Coder-7B
# Python 3.7 final_angle=float(180) # the final angle with which the particle leaves the platform initial_angle=float(60) # the initial angle with which the particle is launched from the platform vyi=float(20) # the vertical initial velocity of the particle gravity=float(9.81) # the acceleration ...
247
pe
1.03.py
9e4c2904bb5c4f3ac672bbe6
Qwen/Qwen2.5-Coder-7B
class Person: """A class to represent people""" def __init__(self, name="", age=0): """Class constructor""" self.name = name self.age = age def __str__(self): return "Person({},{})".format(self.name, self.age) def main(): """Testing code""" jack = Person("Jack", 2...
134
pe
1.03.py
001229a36764a7e85d44f389
Qwen/Qwen2.5-Coder-7B
sentence = input("Please enter a sentence: ") vowels = "aeiouAEIOU" vowel_counter = 0 for letter in sentence: if letter in vowels: vowel_counter += 1 print(vowel_counter)
84
pe
1.03.py
0ef83d42b62e4954eeb09512
Qwen/Qwen2.5-Coder-7B
# Assignment 2 # 10/7/2019 # Imani Ariana Thomas # https://www.sololearn.com # SL Membership: 3147085878007079 # Question: Guess the number # Author: Ryan Steele # Version: 1.1 # Refactor version 1: Including calculations to average time to guess correct number # Description: Guess the correct number between 1 and 5 i...
733
pe
1.03.py
12b9b82b9e1b820acbd8a132
Qwen/Qwen2.5-Coder-7B
bonus = 0.0 salary = float(input("Enter Salary: $")) while salary > 0: if salary >= 10000: bonus = salary * 0.15 salary = salary + bonus elif salary < 10000: bonus = salary * 0.10 salary = salary + bonus print("You have received a bonus of ${:.2f} and your total pay is now ${...
192
pe
1.03.py
deadf97063198eff1a5eb3a1
Qwen/Qwen2.5-Coder-7B
# Python 3.7 h=float(input("Give the height: ")) t=float(input("Give the time in seconds: ")) s=(1/2)*9.81*(t**2) v=9.81*t print("At t =",round(t),"seconds, s =",round(s),"meters, and v =",round(v),"meters per second.") # eof
113
pe
1.03.py
a44efb27a937a890178ad358
Qwen/Qwen2.5-Coder-7B
# sum_numbers.py """ A program that gets a sequence of numbers and calculates the sum of these numbers. """ numbers_list = [] total_numbers = 0 try: user_number = int(input("Enter a number: ")) while user_number != -1: numbers_list.append(user_number) user_number = int(input("Enter a number: "...
224
pe
1.03.py
03d70c7a415c3d6dd7aff2a2
Qwen/Qwen2.5-Coder-7B
""" Program that asks user how many quick picks then generates quick picks """ import random random.seed(10) NUMBERS_PER_LINE = 6 LOWEST_NUMBER = 1 HIGHEST_NUMBER = 45 number_of_quick_picks = int(input("How many quick picks?: ")) print(type(number_of_quick_picks)) for i in range(number_of_quick_picks): quick_pic...
332
pe
1.03.py
0b674e292d0443a664f733ac
Qwen/Qwen2.5-Coder-7B
""" Display the user's weight on the moon if they were to arrive there from Earth. """ user_weight = int(input("What is your weight in kilograms?")) print("Your weight on the moon would be " + str(user_weight * 0.165) + " kilograms.")
87
pe
1.03.py
c3a3b871a11c1b029efcf5c3
Qwen/Qwen2.5-Coder-7B
squares = [] x = 0 while x < 20: x += 1 squares.append(x ** 2) print(squares)
42
pe
1.03.py
cbd43b22c003e6a7ea7b66af
Qwen/Qwen2.5-Coder-7B
user_grade = int(input("Please enter your score: ")) while user_grade >= 0: if user_grade < 50: print("Your score is: {}".format("Bad")) elif user_grade >= 50: print("Your score is: {}".format("Passable")) elif user_grade >= 90: print("Your score is: {}".format("Excellent")) user...
153
pe
1.03.py
cab159611beec3232c57dc17
Qwen/Qwen2.5-Coder-7B
""" CP1404/CP5632 Practical Starter code for cumulative total income program """ def main(): """Display income report for incomes over a given number of months.""" incomes = [] months = int(input("How many months? ")) for month in range(1, months + 1): income = float(input("Enter income for mo...
274
pe
1.03.py
d74714323be8f90580118196
Qwen/Qwen2.5-Coder-7B
# Python 3.7 import random MAX_NUM = 6 MIN_NUM = 1 for j in range(6): random_number = random.randint(MIN_NUM, MAX_NUM) while random_number == MAX_NUM: random_number = random.randint(MIN_NUM, MAX_NUM) print(random_number) # for debugging purpose # eof
124
pe
1.03.py
f9f028fa5850f6fe4ee58a14
Qwen/Qwen2.5-Coder-7B
def rotateImage(a): d=dict() # turn row to col and col to row for x in range(len(a)): for y in range(len(a[x])): if y not in d: d[y]=[a[x][y]] else: d[y].append(a[x][y]) # reverse order result=[] for x in sorted(d.values(...
133
pe
Rotate Image.py
4d304ff068a728c8a36bedfe
Qwen/Qwen2.5-Coder-7B
nums = eval(input()) nums.sort() def dedup(alist): ''' remove duplicate in a list ''' deduped = [] last_elem = None for elem in alist: if last_elem != elem: deduped.append(elem) last_elem = elem return deduped def findLeft(nums, target): ...
519
pe
Rotate Image.py
2d85a72e7b1bd0f9c9744a54
Qwen/Qwen2.5-Coder-7B
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- import itertools print('itertools.cycle:') # A B C A B C ... for x in itertools.cycle('ABC'): if x == 'A': break print(x)
87
pe
Rotate Image.py
189f9aab1369cc316eb2c759
Qwen/Qwen2.5-Coder-7B
from collections import deque import itertools collections = [deque, list, set, frozenset, dict, tuple] dic = dict.fromkeys(collections) for value in itertools.product(*collections): key = None for item in value: key = key + str(item) if key is not None else str(item) dic[key] = value print(dic.k...
108
pe
Rotate Image.py
ae0c473e382c175ee5d73d08
Qwen/Qwen2.5-Coder-7B
def rotate(matrix): matrix[:] = zip(*matrix[::-1]) matrix = [ [1,2,3], [4,5,6], [7,8,9] ] rotate(matrix) print (matrix) matrix = [ [5,1,9,11], [2,4,8,10], [13,3,6,7], [15,14,12,16] ] rotate(m...
163
pe
Rotate Image.py
97dfa6ce83bb918f7ccfaaff
Qwen/Qwen2.5-Coder-7B
# Rotate Image class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ # print(matrix) n = len(matrix) if n == 0: return matrix tmp = [[ma...
210
pe
Rotate Image.py
2033ad67960968f79c1301f5
Qwen/Qwen2.5-Coder-7B
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- """ Given a 2D matrix ( a list of lists ) with values representing pixels, rotate the image by 90 degrees """ class Solution: def rotate(self,matrix): """ Do not return anything, modify matrix in-place instead. """ print("\...
744
pe
Rotate Image.py
2aa7a10af66707e126ad0d86
Qwen/Qwen2.5-Coder-7B
# Given a square matrix, rotate matrix by 90 degrees class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. """ matrix.reverse() for i in range(len(matrix)): ...
119
pe
Rotate Image.py
e2a32f3e6f30cf52136f4ede
Qwen/Qwen2.5-Coder-7B
def rotate_image(matrix): N = len(matrix) matrix.reverse() for i in range(N): for j in range(i): matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] return matrix matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] result = rotate_image(matrix) for row in result: print(row)
109
pe
Rotate Image.py
ea494a23efb24a01c1e6f288
Qwen/Qwen2.5-Coder-7B
class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. """ mlen = len(matrix) cfirst = 0 clast = mlen - 1 for row in matrix: print(row[cfirst:...
182
pe
Rotate Image.py
c1fcfe5dd219fce46166efc6
Qwen/Qwen2.5-Coder-7B
import random def choose(): words = ['rainbow', 'computer', 'science', 'programming', 'python', 'mathematics', 'player', 'condition', 'reverse', 'water', 'board', 'geeks'] pick = random.choice(words) return pick def jumble(word): jumbled = " ".join(random.sample(word, len(wor...
572
pe
new.py
eea77fef7ac157531652d506
Qwen/Qwen2.5-Coder-7B
from itertools import product def iterate(grid): newGrid = set() space = set() for cell in grid: space.update(product(*[[c - 1, c, c + 1] for c in cell])) for cell in space: neighbours = 0 # find the active neighbours of the current spot for potential in product(*[[c ...
323
pe
new.py
c181e39aa4c5bf62267a1345
Qwen/Qwen2.5-Coder-7B
size = int(input("Digite o tamanho do quadrado: ")) square = "" for row in range(size): square += "*" * size square += "\n" print(square) ''' Poderia fazer com dois loops, mas ficou mais complicado... '''
101
pe
new.py
f9a0ded22bcc6c9cb486013a
Qwen/Qwen2.5-Coder-7B
n1=int(input("Give the number of nodes ")) n2=int(input("Give the number of edges ")) def createMatrix(numberOfNodes, listOfEdges): matrix=[] for i in range(numberOfNodes): matrix.append([]) for j in range(numberOfNodes): matrix[i].append(0) for edge in listOfEdges: matr...
330
pe
261_graph_valid_tree.py
52811202c7f9304570e317db
Qwen/Qwen2.5-Coder-7B
# coding=utf-8 class Stack(): def __init__(self,size): self.size=size self.stack=[] def push(self,el): if len(self.stack)==self.size: return False self.stack.append(el) return True def pop(self): if len(self.stack)==0: return None ...
240
pe
261_graph_valid_tree.py
6cd636665692f44784361291
Qwen/Qwen2.5-Coder-7B
class Solution(object): def containsDuplicate(self, nums): return len(set(nums)) != len(nums) nums = [1,2,3,4] #nums = [1,1,1,3,3,4,3,2,4,2] print(Solution().containsDuplicate(nums))
88
pe
261_graph_valid_tree.py
eda70557cc0e0329f2f13c90
Qwen/Qwen2.5-Coder-7B
""" Create a Python class called Rectangle. In this Python Rectangle class, define an initializer (constructor) that takes length and width as parameters and sets them as instance variables. Include methods in the Rectangle class to calculate and return the area and perimeter of the rectangle. The area is calculate...
306
pe
261_graph_valid_tree.py
2764956e2c65d2d9effd8317
Qwen/Qwen2.5-Coder-7B
def func(number): if number % 2 ==0: print(f"{number} is even") elif number % 2 != 0: print(f"{number} is odd") else: print(f"{number} invalid input") func(6)
66
pe
261_graph_valid_tree.py
26081214404d7658d9e93a79
Qwen/Qwen2.5-Coder-7B
# Remove the asterisk from the list nested = [ "*", ["o", ["*", "*"]], "!", ["o", "*", "r"] ] result = [] for item in nested: if type(item) == list: for i in item: result.append(i) else: result.append(item) print(result)
93
pe
261_graph_valid_tree.py
f2ca3cf75fe2bc343baf7891
Qwen/Qwen2.5-Coder-7B
def largest_odd(num): print(''.join(filter(lambda x: x % 2 == 1,map(int,str(num))))) largest_odd(35859)
49
pe
261_graph_valid_tree.py
852d22c6fca64a9cc2e2a916
Qwen/Qwen2.5-Coder-7B
from typing import List class Solution: def sumOddLengthSubarrays(self, arr: List[int]) -> int: _sum = 0 max_len = max(len(arr), 3) list_len = len(arr) for length in range(1,max_len,2): for start in range(0,list_len-length+1): _sum += sum(arr[start:start...
146
pe
261_graph_valid_tree.py
5dca2725ee40f6d7d30a9afc
Qwen/Qwen2.5-Coder-7B
def str_dict(): dict_={} inp=input('Enter string') for i in inp: if i in dict_: dict_[i]+=1 else: dict_[i]=1 return dict_ print(str_dict())
66
pe
261_graph_valid_tree.py
870b51b83fa6057465562229
Qwen/Qwen2.5-Coder-7B
""" Given a string, write a Python program that converts the first letter of each word to uppercase and prints the result to the console. """ def capitalize(sentence:str) -> str: first_char = "" rest = "" for char in sentence: if char.isspace(): first_char += char rest += ch...
167
pe
261_graph_valid_tree.py
dcbb347bc1f63afb9faf2bcb
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(board: dict[tuple[int, int], str]) -> int: """Count the number of cells in a board that differ in their values from their immediate neighbors by checking the surrounding cells. """ differences = 0 surrounding_pairs = [(0, 1), (0, -1), (1, 0), (-1, 0)] for cell_coords,...
185
tp
count_cell_differences.py
80fcbbce764611db18de8b47
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(lst: list[dict[str, str]], column_a: str, column_b: str) -> int: """Count the number of pairs of identical values in adjacent cells for specific column names. """ cell_changes: int = 0 length = len(lst) for i in range(1, length): if lst[i][column_a] == lst[...
125
tp
count_cell_differences.py
a246a033a4b2460d5f2f9e27
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(rows_of_cells: list[list[int]]) -> int: """Given a list of lists containing integers representing cells in a table, count the number of cells that are different from the previous cell in the same row. """ count = 0 for row in rows_of_cells: for i in range(1, len(ro...
115
tp
count_cell_differences.py
c2284d9d8e5ff6b8caa54e62
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(original: list[list[str]], new: list[list[str]]) -> int: """Count the number of cells whose values have changed between two lists of lists. Assume both have the same length and nonempty rows. """ count = 0 for i in range(len(original)): for j in range(len(original[...
128
tp
count_cell_differences.py
54d719e23f6542f362bbae8d
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(matrix: list[list[str]]) -> int: """Count and return the number of cells in a matrix where either the horizontal or vertical neighbor cell has a different value. """ num_rows = len(matrix) num_cols = len(matrix[0]) count = 0 for i in range(num_rows): for j...
211
tp
count_cell_differences.py
ef84333d59727eb78937c826
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(values: list[int]) -> list[int]: """For each cell in the input list, calculate the difference between the respective cell and the previous cell. Return the differences. """ diffs: list[int] = [] for i in range(1, len(values)): diffs.append(values[i] - values[i-...
98
tp
count_cell_differences.py
fc06eb24d526206e9e7e2ef4
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(rows: list[list[int]]) -> int: """Given a nested list of integers representing a grid of cells, return the number of adjacent cells with different values. Neighboring cells are considered as defined by the grid's shape. A cell is adjacent to itself. """ count = 0 r...
410
tp
count_cell_differences.py
032c25e172d8168d45f72d9c
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(values: list[int], column: int) -> dict[str, int]: """Count the number of times the cells in one column of a matrix are either equal or less than the previous cell. """ differences = {"Equal": 0, "Less than": 0} prev_value = values[0] for value in values: if v...
147
tp
count_cell_differences.py
4e888e2cfbf940e85841fbfb
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(str_a: str, str_b: str) -> int: """Count the number of cells that differ between two input strings. Each string represents a table with one or more rows of text cells, delimited by newline characters (\n). Each row contains a sequence of cells separated by one space. Each cell...
313
tp
count_cell_differences.py
12fd3b4aec003b17b1c98689
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(values: list[int]) -> int: """Find the number of pairs of cells whose values differ from each other by more than two. """ count = 0 for i in range(len(values)): for j in range(i + 1, len(values)): if abs(values[i] - values[j]) > 2: count...
101
tp
count_cell_differences.py
ebbf06a0740cd3bf560f8a5a
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(first_cells: list[tuple[str, int]], second_cells: list[tuple[str, int]]) -> int: """Compare the number and values of pairs of cells in two lists, counting how many have changed. """ count: int = 0 for first_cell, second_cell in zip(first_cells, second_cells): if fi...
110
tp
count_cell_differences.py
744b5338a401d036a2118d65
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(nums: list[int]) -> int: """Return the number of pairs of adjacent cells, where the left cell has a strictly smaller value than the right cell. """ differences: int = 0 for i in range(len(nums) - 1): if nums[i] < nums[i+1]: differences += 1 return d...
107
tp
count_cell_differences.py
3077c0f086497c373c592d9f
Qwen/Qwen2.5-Coder-7B
def count_cell_differences(data: list[list[str | int]]) -> int: """Calculate the number of cells that differ by a multiple of 5 between adjacent columns. """ differences = 0 for i in range(1, len(data)): for j in range(len(data[i])): if (data[i][j] - data[i-1][j]) % 5 == 0: ...
117
tp
count_cell_differences.py
74ce7710a81e7483d1b73b68
Qwen/Qwen2.5-Coder-7B
import time import datetime def readFile(): timeInfo = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") start = time.perf_counter() f = open('lp-data.txt', 'r') f.close() # f.read() # no such line end = time.perf_counter() return end - start def compute(): timeInfo = datetime.da...
310
pe
a105_矩形面積.py
2be82f34bb837d79c45f3eeb
Qwen/Qwen2.5-Coder-7B
lst=[1,2,3,4,5,6] pos=3 ele=20 lst.insert(pos,ele) print(lst)
40
pe
a105_矩形面積.py
239840c0e60b9c04c8547d2c
Qwen/Qwen2.5-Coder-7B
""" Using XOR Operation (^): Values in List is defined as integer, therefore, if we add all values together, binary operation will be executed on the binary equivalent of integers. XOR operation means: 0^0 = 0 1^0 = 1 0^1 = 1 1^1 = 0 Therefore, 5 ^ 5 = 5^5^5 ^ 5^5...
266
pe
a105_矩形面積.py
9353c0835e54e017210f39d9
Qwen/Qwen2.5-Coder-7B
class Solution(object): def isPowerOfThree(self, n): """ :type n: int :rtype: bool """ if n==0: return False while n%3==0: n=n/3 if n==1: return True else: return False a=Solution() print(a.isPowerOfThr...
105
pe
a105_矩形面積.py
cc64a6fda44f7c5d2a49b66b
Qwen/Qwen2.5-Coder-7B
""" Enter number of rows: 6 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 7 7 7 8 8 9 """ rows = int(input("Enter number of rows: ")) for i in range(1, rows+1): for j in range(rows-i): print(" ", end=" ") for k in range(i): print(i, end=" ") print() for i i...
189
pe
a105_矩形面積.py
c5d95104ddffff173de953db
Qwen/Qwen2.5-Coder-7B
# 71: The perimeter of a rectangle is 16 print("The perimeter of a rectangle is 16.") def rectangle_perimeter(p): list_p = [] while p > 0: p -= 1 if p % 2 == 0: length = p width = 16 - length list_p.append(length*width) return max(list_p) print(rectangle_p...
119
pe
a105_矩形面積.py
75a8147441349e34a1ca3985
Qwen/Qwen2.5-Coder-7B
def twoSum(nums,target): for i in range(len(nums)): for j in range(i+1,len(nums)): if nums[i] + nums[j] == target: return([i,j]) else: continue print(twoSum([3,2,4],6))
73
pe
a105_矩形面積.py
e4e854689220f71acb59b4b0
Qwen/Qwen2.5-Coder-7B
def main(): high=int(input('')) wide=int(input('')) area=(high*wide) print(area) main()
41
pe
a105_矩形面積.py
f558b465918930a46556b6d9
Qwen/Qwen2.5-Coder-7B
class Solution: def countNodes(self, root): if root==None: return(0) elif root.left == None and root.right == None: return(1) else: return(self.countNodes(root.left) + self.countNodes(root.right)) def m...
451
pe
a105_矩形面積.py
930598eedc166ea836c0aebd
Qwen/Qwen2.5-Coder-7B
def gcd(a, b): while b != 0: a, b = b, a % b return a def find_primitive_roots(p): phi_p = p - 1 factors = set() # Find the prime factors of phi(p) while phi_p % 2 == 0: factors.add(2) phi_p //= 2 for i in range(3, int(phi_p ** 0.5) + 1, 2): wh...
362
pe
reduce_num.py
00a8d059224c7fc7aaf4052d
Qwen/Qwen2.5-Coder-7B
#Ordinary variables def ordinaryVariables(): local_var = 'Good Morning!' global_var = 'Good Evening!' return local_var + global_var print(ordinaryVariables()) #local variables def localVariables(): local_var = 'Good Evening!' return local_var print(localVariables()) #global variab...
498
pe
reduce_num.py
e6eea8a0586af0af53cfcd89
Qwen/Qwen2.5-Coder-7B
#reduce() function:Take two list as input and returns single output import functools numbers = [3, 4, 6, 9, 34, 12] reduce_object = functools.reduce(lambda x, y: x + y, numbers) print("Reduction object",reduce_object) ##Numbers = [3,4,6,9,34,12] ##Reduce_object = functools.reduce(lambda x,y:x+y,numbers) print("S...
166
pe
reduce_num.py
bb83fb482aa8f6637c4bde93
Qwen/Qwen2.5-Coder-7B
def factorial(n): if n == 1: return 1 else: return n * factorial(n-1) for n in range(20): print(n, factorial(n)) # prints 1 1, 2 2, 3 6, 4 24, 5 120, …, 19 121645100408832000, 20 2432902008176640000 # GCD: def gcd(x, y): while y != 0: (x, y) = (y, x % y) return x prin...
165
pe
reduce_num.py
c1143b103719a5d2e8cc89b0
Qwen/Qwen2.5-Coder-7B
class FixedFloat: def __init__(self, amount): self.amount = amount def __repr__(self): return f'<FixedFloat {self.amount:.2f}>' @staticmethod def from_sum(value1, value2): return FixedFloat(value1 + value2) class Euro(FixedFloat): def __init__(self, amount): sup...
239
pe
reduce_num.py
68618b52c51b03f85eb26bb9
Qwen/Qwen2.5-Coder-7B
def reduce_num(num): num //= 2 num //= 3 num //= 4 num //= 5 return num num = int(input("Enter a number ")) print("After reducing numbers " ,reduce_num(num))
83
pe
reduce_num.py
229d931d7155cc2193fcb12f
Qwen/Qwen2.5-Coder-7B
import functools def reduce_num(n): i = 2 while i <= n: if n % i == 0: print(i) n = n // i else: i += 1 reduce_num(100)
82
pe
reduce_num.py
e860f6da2655de06a44de8b6
Qwen/Qwen2.5-Coder-7B
num = int(input("Enter any number ")) reduce_num = num divisor = [] while reduce_num > 0: divisor.append(reduce_num) reduce_num -= 1 reduce_num = num factor = [] for element in divisor: if (reduce_num % element) == 0: factor.append(element) print(factor)
132
pe
reduce_num.py
3ea46005a13f1e0a8aa565e5
Qwen/Qwen2.5-Coder-7B
from random import choice def setWord(): categories = {"persons": ("srk", "priyanka", "tiger", "salam"), "countries": ("france", "germany", "canada", "italy")} category, words = choice(list(categories.items())) word = choice(words) return word, category def getMaskedWord(w...
749
pe
reduce_num.py
0b9c9fa7f979586270d3b11c
Qwen/Qwen2.5-Coder-7B
def reduce_num(n): factors = [] i = 2 while i <= n: while n % i == 0: factors.append(i) n /= i i += 1 return factors #Tests print(reduce_num(19)) print(reduce_num(100)) print(reduce_num(77)) print(reduce_num(81)) print(reduce_num(12345)) print(reduce_num(1))
114
pe
reduce_num.py
23cd2dc5a12886efe790626b
Qwen/Qwen2.5-Coder-7B
def to_digit(n): return [int(x) for x in str(n)] def sum_digits(n): return sum(to_digit(n)) def to_number(digits): n = "".join(str(i) for i in digits) return int(n) print(sum_digits(13)) print(sum_digits(123456789)) print(to_number(to_digit(123))) print(to_number([1,2,3,4,5,6,7,8,9]))
150
pe
reduce_num.py
bda1072b26650302a83b33d1
Qwen/Qwen2.5-Coder-7B
#Prime number or not x = int(input("Enter any number : ")) count = 0 divisor = int(1) while divisor <= x: if(x%divisor == 0): count += 1 divisor+=1 if count == 2: print("number is prime") else: print("number is not prime")
100
pe
reduce_num.py
0e619b55788960d43c1795b4
Qwen/Qwen2.5-Coder-7B
def reduce_num(x): while x > 0: print(x) if x % 2 == 0: x = x // 2 else: x = x - 1 reduce_num(10)
73
pe
reduce_num.py
ce1ab833a57fe4e446b1bfcc
Qwen/Qwen2.5-Coder-7B
#reduce() function:returns a single value. It applies a function on a list and reduces the list to a single value. from functools import reduce add_five = lambda x: x + 5 print(add_five(5)) multiply_ten = lambda x: x * 10 print(multiply_ten(5)) sum_five_ten = lambda x,y: x + y print(sum_five_ten(5, 10)) ...
334
pe
reduce_num.py
9df780b49cd671c4b7d5039a
Qwen/Qwen2.5-Coder-7B
# Using Logical operator and function def canVote(age): return age >= 18 name = input("Enter Name: ") age = int(input("Enter Age: ")) candidate = input("Are you a candidate? ") preclude = input("Have you been convicted of a crime? ") can_apply = True if name == "" or age < 0: can_apply = False if no...
295
pe
reduce_num.py
293d4ae5b74572192bba1d80
Qwen/Qwen2.5-Coder-7B
# loop through set, remove number if number is smaller than current number # elif continue for loop listInput = [1, 2, 3, 4, 3] listOutput = [1, 2, 3, 4] # lis = listInput # lis.sort() # print(lis) lis = [] lis.append(listInput[0]) for i in listInput: if lis[0] > i: # if lis[0] < i: lis.remove(lis[0])...
175
pe
module6Discussion_Temps.py
f70e69a5f5e5e63704fc24e9
Qwen/Qwen2.5-Coder-7B
# Factorial of given number num = int(input("Enter the number to find factorial: ")) fact = 1 for i in range(1, num+1): fact *= i print("Factorial of the number is : {} ".format(fact))
75
pe
module6Discussion_Temps.py
3a3ef4e772837730a37da017
Qwen/Qwen2.5-Coder-7B
numbers = list(range(1, 100)) for i in numbers: if i % 3 == 0: print("fizz") elif i % 5 == 0: print("buzz") elif i % 3 == 0 and i % 5 == 0: print("fizzbuzz") else: print(i) numbers = list(range(1,101)) for i in numbers: print("{} {}".format('fizz' * (i%3 ==0), 'buzz'...
136
pe
module6Discussion_Temps.py
d99a0ecedf3d7b8021c6f56e
Qwen/Qwen2.5-Coder-7B
def towerOfHanoi(height,src,dst,temp): if height >= 1: towerOfHanoi(height-1,src,temp,dst) print('Move disc '+ str(height)+' from '+ src + ' to '+ dst) towerOfHanoi(height-1,temp,dst,src) towerOfHanoi(2,'A','C','B')
123
pe
module6Discussion_Temps.py
7841e0865119be7c5e4deaf9
Qwen/Qwen2.5-Coder-7B
sum_positive = 0 while True: grade = int(input("Please enter grades: (-1 to exit) ")) if grade == -1: break if grade > 0: sum_positive += grade else: print("invalid grade") if sum_positive > 0: print("Sum of the grades are: {}".format(sum_positive))
120
pe
module6Discussion_Temps.py
17e0ea65a9f6a162ee6926ff
Qwen/Qwen2.5-Coder-7B
import random def binary_search(search_for): sorted_array = random.sample(range(100), 5) sorted_array.sort() low = 0 high = len(sorted_array) - 1 while low <= high: mid = low + (high - low) // 2 # integer division to avoid overflow guess = sorted_array[mid] if guess == ...
178
pe
module6Discussion_Temps.py
4e3eecaa5b12cc1dfe35562c
Qwen/Qwen2.5-Coder-7B
def extract_numeric_fields(lines: list[str]) -> list[dict[str, int | str]]: """Given a list of lines containing personal information, return a list of dictionaries, each representing a person's details. Each dictionary has two keys - 'Age' and 'Mobile'. Only lines containing these fields are processed. ...
214
tp
extract_numeric_fields.py
3c48d57a46422377e36cf377
Qwen/Qwen2.5-Coder-7B
def extract_numeric_fields(text: str) -> tuple[int, float]: """Given a string containing a price with an optional dollar sign, extract and return the price as an integer and the amount as a float after splitting at the dollar sign. """ price_str, amount_str = text.replace('$', '').split('.') pri...
142
tp
extract_numeric_fields.py
d8e8f1490f24dd67e23b343f
Qwen/Qwen2.5-Coder-7B
def extract_numeric_fields(strings: list[str]) -> list[tuple[int, int]]: """Extract each string from a list into a tuple consisting of the numbers of digits and non-digit characters in the string. """ return [(len([c for c in s if c.isdigit()]), len([c for c in s if not c.isdigit()])) for s in strings]
114
tp
extract_numeric_fields.py
2636cf82481321a5dcc38487
Qwen/Qwen2.5-Coder-7B
def extract_numeric_fields(string: str) -> list[str]: """Extract fields of numbers from a string into a list of numeric fields, excluding any fields with embedded nonnumeric characters, while handling mixed alphabetic and numeric characters within strings appropriately. """ result: list[str] = [] ...
164
tp
extract_numeric_fields.py
4af3a94b34f37c473df75a68
Qwen/Qwen2.5-Coder-7B
def extract_numeric_fields(grid: list[list[Union[str, float]]]) -> list[tuple[int, float]]: """Extract all numeric cells in a square grid (list of lists) and return them as tuples (column index, cell value), ordered by column and then row index. """ numeric_cells = [] for row_index, row in enumerate...
153
tp
extract_numeric_fields.py
ad1786b703fe73a64eb9c16d
Qwen/Qwen2.5-Coder-7B