???
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")
All generations.
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")
def add(a, b):
return a + b
Please under 1000 chars
def abc():
return "abcdefghijklmnopqrstuvwxyz"
abc()
def get_iq(a, b):
return (a + b)/2
get_iq(192, 176)
def a():
print(x)
x = 2
a()
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'
The function Allen.Allen() prints the string "Allen is awesome"
def name(name):
return name
name("Sherry")
def f(a, b):
return a + b
Python
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)
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()
The function chk_odd takes one argument num and checks if it is an odd number. If yes it returns true and else it returns false
for i in range(1, 20):
for j in range(1, 20):
print(i * j)
def times(number):
for i in range(1, 21):
print(number * i)
times(1)
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)
def iq(a, b, c):
return (a + b + c)/3
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()
def grade(score):
if score > 100 or score < 0:
return "error"
elif score >= 89:
return "A"
elif score >= 79:
return "B"
elif score >= 69:
return "C"
elif score >= 59:
return "D"
else:
return "E"
print(grade(80))
### Basic usage
for i in range(1, 20):
for j in range(1, 20):
if j > i:
print(i * j)
def sing():
return "never gonna give you up"
sing()
def times_table(a):
return [[i*a for i in range(1, 20)]]
times_table(5)
for i in range(1, 20):
print(f'{i} x {i} = {i*i}')
def storage(gb):
return gb * 1000
storage(1)
def square(x):
return x * x
def times_table(n):
for i in range(1, n + 1):
print(i, "times table")
for j in range(1, n + 1):
print(i, "*", j, "=", i * j)
print()
times_table(999)
3
def GB_to_KB(a):
return a * 1024 * 1024 * 1024
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))
def iq(a, b, c):
return (a + b + c)
iq(1, 2, 3)
def table(num):
for i in range(1,11):
print(f"{num} x {i} = {num*i}")
table(999)
def square(a):
return a * a
func times(a: Int, b: Int) -> Int {
return a * b
}
times(1, b:19)
chk_odd is a function that takes one parameter num and returns whether the parameter is an odd or not.
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)
//
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
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.
def add(a, b):
return a + b
add(1, 2)
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)
def new_line():
print("")
new_line()
def times(n):
for i in range(1, 20):
print(i, '*', n, '=', i * n)
times(5)
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")
def times(n):
for i in range(1, 20):
print(n, 'x', i, '=', n*i)
times(3)
def times_table(n):
for i in range(1, 10):
print(n * i)
times_table(999)
def f(x, y):
if x > y:
return x
else:
return y
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
def add_10(num):
return num + 10
add_10(10)
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")
returns "abcdefghijklmnopqrstuvwxyz"
def add2(a, b):
return a + b
def add2(a, b, c):
return add2(a, b) + c
add2(1, 2, 3)
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)
def square(a):
return a * a
def times_table(n):
return [x*n for x in range(1, 20)]
times_table(1)
def mom():
print("You did a great job!")
print("I'm proud of you.")
print("I love you!")
mom()
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)
def storage(gb):
return f"You'll need {gb} GB to store all your selfies."
storage(251)
def times_table(times):
for i in range(1, 1000):
print(f"{i} times {times} is {i*times}")
def print_kwargs(**kwargs):
print(kwargs)
print_kwargs(kwargs_1="Shark", kwargs_2=4.5, kwargs_3=True)
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()
def disk_size_in_GB(size_in_TB):
return size_in_TB * 1024
disk_size_in_GB(0.25)
def times_table(times):
for i in range(1, 20):
print(f"{i} * {times} = {i * times}")
times_table(4)
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)
def times_table(num):
for i in range(1, 20):
print(str(i) + " x " + str(num) + " = " + str(num * i))
times_table(5)
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)
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)
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)
c++
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)
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")
def storage(gb):
return gb * 1000
storage(251)
def wow(a, b, c):
return a * b * c
wow(1, 2, 3)
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
def jhbgfygu(a):
return 'jhbgfygu' * a
jhbgfygu(5)
def dummy():
return None
print(dummy())
def add_unique(x, my_list = []):
my_list.append(x)
return my_list
add_unique(1)
add_unique(2)
add_unique(3)
def chk_odd(num):
if num % 2 == 0:
return True
else:
return False
chk_odd(3)
def disk_space(space, unit):
return space * 2**30 if unit.upper() == 'GB' else space * 2**20
disk_space(251, 'GB')
def what(n):
if n > 0:
return "pos"
elif n < 0:
return "neg"
else:
return "zero"
what(-1)
def add(a, b):
return a + b
add(1, "2")
def function_name(parameters):
"""
Docstring explaining the function
"""
# Do stuff here
# Return desired result
def add(a, b):
return a + b
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)
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
def produce(food, iron):
while food > 0:
food = food - 1
print(food)
iron = iron - 1
print(iron)
produce(100, 100)
def add(a, b):
return a + b
add('1', 2)
#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;
}
func times(n int) {
for i := 1; i <= 19; i++ {
fmt.Println(n, "x", i, "=", n*i)
}
}
def generate_function(description):
pass
gen_add = generate_function('add two numbers')
gen_add(1, 2) # 3
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:
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")
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)
def army_survival(food, iron):
while(food > 0):
print("You are still alive.")
food = food - 1
iron = iron - 1
print("You have died.")
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
Generate
More than just a code generator. A tool that helps you with a wide range of tasks. All in one place.
Function from Description
Text Description to SQL Command
Translate Languages
Generate HTML from Description
Code to Explanation
Fix invalid Code
Get Test for Code
Class from Description
Regex from Description
Regex to Explanation
Git Command from Description
Linux Command
Function from Docstring
Add typing to code
Get Language from Code
Time complexity
CSS from Description
Meta Tags from Description