Allen Chen

All generations.

generate functionThu, 30 Mar 2023

???

def my_function(): print("Hello from a function") my_function() def my_function(fname): print(fname + " Refsnes") my_function("Emil") my_function("Tobias") my_function("Linus")

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def sim_food(food_produce): food = 100 iron = 100 for time in range(0,600,10): food = food + food_produce food = food - (time/60) if food < 0: return 'you died' return 'you survived'

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.

food = 100 iron = 100 def food_per_second(time): return time / 10 def iron_per_second(time): return time / 100 def food_iron_counter(time): global food global iron food = food - food_per_second(time) iron = iron - iron_per_second(time) return food, iron food_iron_counter(10)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.

food = 100 iron = 100 time = 0 def send_supplies(): global food global iron global time food = food - 1 iron = iron - 1 time = time + 10 def produce_food(): global food global time food = food + 1 time = time + 100 def produce_iron(): global iron global time iron = iron + 1 time = time + 100 def check_for_death(): global food global iron if food <= 0 and iron <= 0: print("You are dead") print("The army is dead") exit() elif food <= 0: print("You are dead") print("The army is still alive") exit() elif iron <= 0: print("You are still alive") print("The army is dead") exit() send_supplies() produce_food() produce_iron()

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.

food = 100 iron = 100 timestep = 0 max_time = 100000 while food > 0 and iron > 0 and timestep < max_time: time.sleep(10) food = food + 1 time.sleep(100) iron = iron + 1 time.sleep(60) food = food - 1 timestep = timestep + 1 print(food, iron, timestep)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.

def army(): food = 100 iron = 100 for i in range(0, 100000): food -= 1/60 iron -= 1/100 if food <= 0 or iron <= 0: return "you have died" return "you have survived" army()

Python
View
generate functionSun, 02 Apr 2023

the 1 to 19 times table

def times(n): return n * 19 print(times(1)) print(times(2)) print(times(3)) print(times(4)) print(times(5)) print(times(6)) print(times(7)) print(times(8)) print(times(9)) print(times(10)) print(times(11)) print(times(12)) print(times(13)) print(times(14)) print(times(15)) print(times(16)) print(times(17)) print(times(18)) print(times(19)) print(times(20))

Python
View
generate functionSun, 02 Apr 2023

the 1 to 19 times table

package main import "fmt" type Num int func main() { for i := 1; i <= 19; i++ { //fmt.Println(i * 1) //fmt.Println(i * 2) //fmt.Println(i * 3) //fmt.Println(i * 4) //fmt.Println(i * 5) //fmt.Println(i * 6) //fmt.Println(i * 7) //fmt.Println(i * 8) //fmt.Println(i * 9) //fmt.Println(i * 10) //fmt.Println(i * 11) //fmt.Println(i * 12) //fmt.Println(i * 13) //fmt.Println(i * 14) //fmt.Println(i * 15) //

generate functionMon, 03 Apr 2023

251 GB Flash Storage

def convert_storage(size): unit=['KB', 'MB', 'GB', 'TB'] i=0 while size > 1024: size /= 1024 i += 1 return str(size) + unit[i] print(convert_storage(1099511627776)) # Should be 1 TB

Python
View
code to explanationSun, 02 Apr 2023

def food_timer(food,seconds): return food + int(seconds / 10) def iron_timer(iron,seconds): return iron + int(seconds / 100) def army_timer(food,seconds): return food - int(seconds / 60) def survival(food, iron, seconds): army = True while army: print(food,iron) food = food_timer(food,seconds) iron = iron_timer(iron,seconds) food = army_timer(food,seconds) if food <= 0: print('You are dead') army = False if iron <= 0: print('You lost the war') army = False survival(100,100,100000)

The function survival takes three arguments food, iron, and seconds. Define the variable army to True and create a while loop. The while loop takes the food, iron, and seconds. The while loop prints the value of food and iron. The while loop uses the function food_timer, iron_timer, and army_timer to update the value of food and iron. If the value of food is less than or equal to zero print 'You are dead'. If the value of iron is less than or equal to zero print 'You lost the war.

generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def army(food, iron, food_production, iron_production): while True: if food < 0: return "You died." else: food_production = food_production + 10 iron_production = iron_production + 100 food = food - 1 if food_production == 10: food = food + 1 food_production = 0 if iron_production == 100: iron = iron + 1 iron_production = 0 return "food = %s , iron = %s" % (food, iron) food = 100 iron = 100 food_production = 0 iron_production = 0 army(food, iron, food_production, iron_production)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def survival(food, iron): seconds = 0 while food > 0 and iron > 0: seconds += 1 food -= 1/60 iron -= 1/1000 if seconds % 10 == 0: food += 1 if seconds % 100 == 0: iron += 1 if food <= 0: print("you die of starvation") if iron <= 0: print("you die of iron deficiency")

Python
View
generate functionThu, 30 Mar 2023

!!!

def add_one(a): return a + 1 add_one(10) # Write a function called add_one that adds 1 to its input and returns that output >>> def add_one(num): ... return num + 1 ... >>> add_one(10) 11

Python
View
generate functionSat, 08 Apr 2023

how to get your iq

def iq_test(numbers): nums = numbers.split(" ") evens = [] odds = [] for num in nums: if num % 2 == 0: evens.append(num) else: odds.append(num) if len(evens) > len(odds): return nums.index(odds[0]) + 1 else: return nums.index(evens[0]) + 1 iq_test("2 4 7 8 10")

Python
View
generate functionThu, 30 Mar 2023

def add2(a, b): return a + b def add2(a, b, c): return add2(a, b) + c add2(1, 2, 3)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.

import time def fight(time_passed): food = 100 iron = 100 while True: if food == 0 or iron == 0: print("you died") break time.sleep(1) time_passed += 1 food -= 0.1 if time_passed % 100 == 0: iron -= 1 print(f"food: {food:.1f}, iron: {iron}") fight(0)

Python
View
generate functionThu, 30 Mar 2023

mom

def mom(): print("You did a great job!") print("I'm proud of you.") print("I love you!") mom()

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def factory(time, food): for i in range(time): if food > 0: food = food - 1 else: return "you are dead" return food factory(120, 100)

Python
View
generate functionThu, 30 Mar 2023

!!!

def print_kwargs(**kwargs): print(kwargs) print_kwargs(kwargs_1="Shark", kwargs_2=4.5, kwargs_3=True)

Python
View
generate functionThu, 30 Mar 2023

a tic tac toe game

def tic_tac_toe(): while True: move = get_players_move() if move == "quit": break make_move(move) if game_is_over(): announce_winner() break tic_tac_toe()

Python
View
generate functionMon, 03 Apr 2023

251 GB Storage

def convert_size(size_bytes): if size_bytes == 0: return "0B" size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") i = int(math.floor(math.log(size_bytes, 1024))) p = math.pow(1024, i) s = round(size_bytes / p, 2) return "%s %s" % (s, size_name[i]) convert_size(25165824000)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def food(x): return 100 - 10 * x def iron(x): return 100 - 100 * x def life(x, y, z): return food(x) - y, iron(x) - z life(10, 60, 100)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def food_timer(food,seconds): return food + int(seconds / 10) def iron_timer(iron,seconds): return iron + int(seconds / 100) def army_timer(food,seconds): return food - int(seconds / 60) def survival(food, iron, seconds): army = True while army: print(food,iron) food = food_timer(food,seconds) iron = iron_timer(iron,seconds) food = army_timer(food,seconds) if food <= 0: print('You are dead') army = False if iron <= 0: print('You lost the war') army = False survival(100,100,100000)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.

def army_supplies(food, iron, time_elapsed): total_food = food total_iron = iron while True: if time_elapsed % 10 == 0: total_food += 1 elif time_elapsed % 100 == 0: total_iron += 1 elif time_elapsed % 60 == 0: total_food -= 1 if total_food == 0: print("you died") break elif total_iron == 0: print("you died") break time_elapsed += 1 army_supplies(100, 100, 0)

Python
View
generate functionThu, 30 Mar 2023

!!!

def add(a, b): sum = a + b print("The sum of {a} and {b} is {sum}".format(a = a, b = b, sum = sum)) add(1, 2)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def foodproduction(a): return a*10 def ironproduction(b): return b*100 def foodconsumption(c): return c*60 def supply(a1, b1, c1): food = 100 iron=100 while food>0 and iron>0: foodproduction(a1): ironproduction(b1): foodconsumption(c1): food = food - foodconsumption(c1) + foodproduction(a1) iron = iron - ironproduction(b1) if food <= 0: print("You ran out of food, you died") elif iron <= 0: print("You ran out of iron, you died") else: print("You survived")

Python
View
generate functionSat, 08 Apr 2023

GRADE 3 SASMO 2023 简体 (Examination time is:2023-04-08 14:00) 姓名:陈艾纶 准考证号:086230002639 手机:15300601005 There is still a long way to go 01 min 25 s Waiting for the exam

def grade_3(question_id,answer): if question_id == 1: if answer == "C": return 1 else: return 0 elif question_id == 2: if answer == "A": return 1 else: return 0 elif question_id == 3: if answer == "B": return 1 else: return 0 elif question_id == 4: if answer == "D": return 1 else: return 0 elif question_id == 5: if answer == "C": return 1 else: return 0 elif question_id == 6: if answer == "D": return 1 else: return 0 elif question_id == 7: if answer == "A": return 1 else: return 0 elif question_id == 8: if answer == "B": return 1 else: return

Python
View
generate functionThu, 30 Mar 2023

!!!

def add_unique(x, my_list = []): my_list.append(x) return my_list add_unique(1) add_unique(2) add_unique(3)

Python
View
generate functionThu, 30 Mar 2023

what

def what(n): if n > 0: return "pos" elif n < 0: return "neg" else: return "zero" what(-1)

Python
View
generate functionThu, 30 Mar 2023

!!!

def function_name(parameters): """ Docstring explaining the function """ # Do stuff here # Return desired result

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def army_survive(food, iron): time = 0 while True: if time % 10 == 0: food += 1 if time % 60 == 0: food -= 1 if food < 0: return "Your army died" if time % 100 == 0: iron += 1 if time % 60 == 0: iron -= 1 if iron < 0: return "Your army died" time += 1 army_survive(100, 100)

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.

def army_supplies(time): iron = 100 food = 100 while time > 0: food -= 1 time -= 60 if time % 100 == 0: iron += 1 if time % 10 == 0: food += 1 if food <= 0: print('You died of hunger') return elif iron <= 0: print('You can not fight') return return food, iron

Python
View
generate functionSun, 02 Apr 2023

the 1 to 19 times table

#include <stdio.h> int main() { int num; printf("Enter an integer: "); scanf("%d",&num); for(int i=1; i <= 10; ++i) { printf("%d * %d = %d \n", num, i, num*i); } return 0; }

C++
View
fix invalid codeSun, 02 Apr 2023

import time import random print('you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food.') def ac (x,y) f=x i=y print('food:'f 'iron:'i) def gc (x) if f<=0: print('fail!')

Depending on the code, you might also need to use a semi-colon. ### How do I use a semi-colon? To use a semi-colon, you should use a semi-colon instead of a colon, and then `end` should be replaced with `;` For example:

generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def army(food_p, iron_p): t = 0 while t < 60: if food > 0 and iron > 0: food = food + food_p iron = iron + iron_p food = food - 1 iron = iron - 1 else: print(t, "seconds,all dead") break t = t + 1 print(t, food, iron, "seconds")

Python
View
generate functionSun, 02 Apr 2023

you are helping an army. if you don't send supplies, you would die. if the food drops to 0 all would die. if you run out of iron, the army could not fight. you will start with 100 food and 100 iron. it takes 10 seconds to produce 1 food and 100 seconds to produce 1 iron.The army eats 1 food every 60 sec.you decide how many food we produce.

def army(food, iron, seconds): while True: food -= 1 seconds += 60 if seconds % 10 == 0: food += 1 if seconds % 100 == 0: iron += 1 if food == 0 or iron == 0: print(food, iron) return army(food, iron, seconds) army(100, 100, 0)

Python
View
generate functionThu, 30 Mar 2023

def add(a, b): return a + b def subtract(a, b): return a - b # use add and subtract to create the following functions def multiply(a, b): return a * b def divide(a, b): return a / b def square(a): return a * a

Python
View

Questions about programming?Chat with your personal AI assistant