My code works as intended, but the bot code checker displays an error "The 'budget' function should be defined with 1 argument, I currently found 0 arguments in the definition."
I've tried to come up with multiple solutions, but none work.
invited = input("Mitu kutsutud?: ")
coming = input("Mitu tuleb?: ")
food = 10
room = 55
def budget():
max_budget = 10 * int(kutsutud) + 55
min_budget = 10 * int(tuleb) + 55
print(str(max_budget) + " eurot")
print(str(min_budget) + " eurot")
budget()
invited = input("Mitu kutsutud?: ")
coming = input("Mitu tuleb?: ")
food = 10
room = 55
#This function needs 2 arguments assuming you are
#trying to use kutsutud and tuleb as the int values in your function
#This also assumes that min and max budget are unchanging
#Also the data above cannot be used because the exist before the function was created
def budget(exampleA,exampleB):
max_budget = 10 * int(kutsutud) + 55
min_budget = 10 * int(tuleb) + 55
print(str(max_budget) + " eurot")
print(str(min_budget) + " eurot")
budget()
##################################################################################
##Make your function here.
def budget(exampleA,exampleB):
max_budget = 10 * int(kutsutud) + 55
min_budget = 10 * int(tuleb) + 55
print(str(max_budget) + " eurot")
print(str(min_budget) + " eurot")
# Set Vars here
invited = input("Mitu kutsutud?: ")
coming = input("Mitu tuleb?: ")
food = 10
room = 55
#Call function here
budget(invited, coming)
Hope this helps based on what I understood from the question.
Related
I'm not sure if there is actually an error here, but I (out of curiosity) created a program that calculated how many people across ~241 generations had... let's say intimate relations before just one person in Generation Z was born, and then following that how many people had intimate relations before the whole population of Generation Z was born.
Prerequisites: There are 72.1 million people in Gen Z, and one Generation lasts 25 years. All relationships are monogamous. Each couple has one child.
import time
#I made this program out of pure curiousity (I'm not lewd, I promise) and I found it pretty interesting.
#Bunny art
print(" z")
print(" z")
print(" z")
print("(\(\ ")
print("(– -)")
print("(‘)(’)")
#Variable Declarations
generationLength = 25
totalYears = 6026
numberOfGenerations = totalYears / generationLength
numberOfCalculations = 0
numberOfPeople = 1
numberOfPeopleOnEarth = 7750000000
numberOfPeopleInThisGeneration = 72100000
def howManyPeopleHadSexBeforeICameIntoExistence():
#Mathematics
numberOfCalculations = 0
while (numberOfCalculations < numberOfGenerations):
numberOfPeople = numberOfGenerations * 2
numberOfCalculations = numberOfCalculations + 1
#Output
time.sleep(2)
print("\nCalculating pointless knowledge...")
time.sleep(2)
print("At least " + str(round(numberOfPeople)) + " people in had sex before one person in Generation Z was born.")
#Mathematics
total = round(numberOfPeople * numberOfPeopleInThisGeneration)
#Output
time.sleep(2)
print("\nCalculating extra trivia...")
time.sleep(2)
print("At least " + str(total) + " had sex before every person in Generation Z was born.")
howManyPeopleHadSexBeforeICameIntoExistence()
import time
# I made this program out of pure curiousity (I'm lewd, I promise) and I found it pretty interesting.
# Bunny art
print(" z")
print(" z")
print(" z")
print("(\(\ ")
print("(– -)")
print("(‘)(’)")
# Variable Declarations
generationLength = 25
totalYears = 6026
numberOfGenerations = totalYears / generationLength
numberOfPeopleOnEarth = 7750000000
numberOfPeopleInThisGeneration = 72100000
percentage_of_current_generation = numberOfPeopleInThisGeneration/numberOfPeopleOnEarth
max_age = 100
def howManyPeopleHadSexBeforeICameIntoExistence():
numberOfPeople = numberOfPeopleInThisGeneration * (2 ** numberOfGenerations) - numberOfPeopleInThisGeneration
# Output
time.sleep(2)
print("\nCalculating pointless knowledge...")
time.sleep(2)
print("At least " + str(round(numberOfPeople)) + " people in history had sex before one person in Generation Z was born.")
# Mathematics
total_alive = round(numberOfPeopleInThisGeneration * (2 ** (max_age/generationLength)) - 1)
# Output
time.sleep(2)
print("\nCalculating extra trivia...")
time.sleep(2)
print("At least " + str(total_alive) + " people currently alive had sex before every person in Generation Z was born.")
howManyPeopleHadSexBeforeICameIntoExistence()
I have a code that is ridiculously long and I need to use it in many methods. I think there's definitely a better way to write it. But I'm struggling to find it. What the code does is that it:
Takes 12 numbers
It inputs them in a list(let us call it count)
Creates 12 stars variables
It needs to create some sort of matrix that looks like this:
******* count1
******** count2
********** maxcount (could be any count from count1 to 12, as long as it is the maximum
***** count5
etc..
So to explain that, we have 12 count variables, I needed to take the largest variable of them, so I put them in a list. After putting them in a list, I selected the max(count) in order to build my astericks representation.
The maximum number of astericks possible is 10. THerefore, the maximum amongst the 12 counts should have 10 stars next to it, and all the others will have their stars relatively.
This is my code, but it doesn't seem optimal at all to me, lots of variables created and initialized as well as it takes some time.
count = list()
count.append(count1)
count.append(count2)
count.append(count3)
count.append(count4)
count.append(count5)
count.append(count6)
count.append(count7)
count.append(count8)
count.append(count9)
count.append(count10)
count.append(count11)
count.append(count12)
stars1 = 0
stars2 = 0
stars3 = 0
stars4 = 0
stars5 = 0
stars6 = 0
stars7 = 0
stars8 = 0
stars9 = 0
stars10 = 0
stars11 = 0
stars12 = 0
stars1 = int((count1 * 10) / max(count))
stars2 = int((count2 * 10) / max(count))
stars3 = int(count3 * 10 / max(count))
stars4 = int(count4 * 10 / max(count))
stars5 = int(count5 * 10 / max(count))
stars6 = int(count6 * 10 / max(count))
stars7 = int(count7 * 10 / max(count))
stars8 = int(count8 * 10 / max(count))
stars9 = int(count9 * 10 / max(count))
stars10 = int(count10 * 10 / max(count))
stars11 = int(count11 * 10 / max(count))
stars12 = int(count12 * 10 / max(count))
astericks1 = ""
astericks2 = ""
astericks3 = ""
astericks4 = ""
astericks5 = ""
astericks6 = ""
astericks7 = ""
astericks8 = ""
astericks9 = ""
astericks10 = ""
astericks11 = ""
astericks12 = ""
for i in range(1, 11):
if (i <= stars1):
astericks1 += "*"
else:
astericks1 += " "
if (i <= stars2):
astericks2 += "*"
astericks2 += " "
if (i <= stars3):
astericks3 += "*"
else:
astericks3 += " "
if (i <= stars4):
astericks4 += "*"
else:
astericks4 += " "
if (i <= stars5):
astericks5 += "*"
else:
astericks5 += " "
if (i <= stars6):
astericks6 += "*"
else:
astericks6 += " "
if (i <= stars7):
astericks7 += "*"
else:
astericks7 += " "
if (i <= stars8):
astericks8 += "*"
else:
astericks8 += " "
if (i <= stars9):
astericks9 += "*"
else:
astericks9 += " "
if (i <= stars10):
astericks10 += "*"
else:
astericks10 += " "
if (i <= stars11):
astericks11 += "*"
else:
astericks11 += " "
if (i <= stars12):
astericks12 += "*"
else:
astericks12 += " "
First of all this kind of if,elif statements and variable creations are generally bad coding practice. Secondly, as a little advice you should always think that I can create same functionality with the list instead of two different variables for the same reason (count1,count2, etc.).
As I understand from your code you print maximum 10 stars for max value. So the code below should produce same behavior with yours using list comprehensions. Also I should mention that it can be written more efficiently but I wanted to be clear and simple for you.
variable_num = 12
count = [int(input()) for i in range(variable_num)]
max_num = max(count)
count = [(i*10)//max_num for i in count]
for ind,i in enumerate(count):
print("{} count {}".format(int(i)*"*",ind))
As simple as:
# Get 12 numbers as input
s = input("Input 12 numbers separated by a white space")
# Save them in a list and calculate the maximum
nums = [int(item) for item in s.split()]
max_num = max(nums)
for idx, item in enumerate(nums):
# Calcuate number of stars, ensuring number of stars are never more then 10
num_stars = int(item * 10 / max_num)
# print the stars
print('*' * num_stars, 'count{}'.format(idx))
Sample output will be
Input 12 numbers separated by a white space1 2 3 4 5 6 1 2 3 4 5 6
* count0
*** count1
***** count2
****** count3
******** count4
********** count5
* count6
*** count7
***** count8
****** count9
******** count10
********** count11
I'm currently having a problem with a function in python. This is my code before I tried putting it in a function:
for i in range(4):
for y in Days:
for x in "ABCDEF":
data = input("What was the punctuality for bus " + x + " on " + str(y) + ", Week " + str(Week) + "? ")
Bus = "Bus" + str(x)
Buses[Bus].append(str(data))
print()
Week += 1
And it works like it is meant to, however I tried putting it in a function:
def InputData():
for i in range(4):
for y in Days:
for x in "ABCDEF":
data = input("What was the punctuality for bus " + x + " on " + str(y) + ", Week " + str(Week) + "? ")
Bus = "Bus" + str(x)
Buses[Bus].append(str(data))
print()
Week += 1
And I am getting errors about the whole Week += 1 part. They say:
[pyflakes] local variable 'Week' (defined in enclosing scope on line 11)
referenced before assignment
[pyflakes] local variable 'Week' is assigned to but never used
Any help would be greatly appreciated.
Week = 0
Put this at the beginning of your code.
I'm making a program that scrapes local bus times from a real time information server and prints them. In order to return all the bus times, it does this:
while i < len(info["results"]):
print "Route Number:" + " " + info['results'][i]['route']
print "Due in" + " " + info["results"][i]["duetime"] + " " + "minutes." + "\n"
i = i + 1
This works fine, and returns all of the results, one by one like so:
Route Number: 83
Due in 12 minutes.
Route Number: 83
Due in 25 minutes.
Route Number: 83A
Due in 39 minutes.
Route Number: 83
Due in 55 minutes.
However, as I'm using this feature within another script, I turned the code to fetch times and return them into a function:
def fetchtime(stopnum):
data = "?stopid={}".format(stopnum)+"&format=json"
content = "https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation"
req = urllib2.urlopen(content + data + "?")
i = 0
info = json.load(req)
if len(info["results"]) == 0:
return "Sorry, there's no real time info for this stop!"
while i < len(info["results"]):
return "Route Number:" + " " + str(info['results'][i]['route']) + "\n" + "Due in" + " " + str(info["results"][i]["duetime"]) + " " + "minutes." + "\n"
i = i + 1
This works, however it only returns the first bus from the list given by the server, instead of however many buses there may be. How do I get the printed result of the function to return the info supplied in each iteration of the loop?
Can you not just make a list and return the list?
businfo = list()
while i < len(info["results"]):
businfo.append("Route Number:" + " " + str(info['results'][i]['route']) + "\n" + "Due in" + " " + str(info["results"][i]["duetime"]) + " " + "minutes." + "\n")
i = i + 1
return businfo
You will have to edit the printing commands that this function returns to.
I would suggest you to use the yield statement instead return in fetchtime function.
Something like:
def fetchtime(stopnum):
data = "?stopid={}".format(stopnum)+"&format=json"
content = "https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation"
req = urllib2.urlopen(content + data + "?")
i = 0
info = json.load(req)
if len(info["results"]) == 0:
yield "Sorry, there's no real time info for this stop!"
while i < len(info["results"]):
yield "Route Number:" + " " + str(info['results'][i]['route']) + "\n" + "Due in" + " " + str(info["results"][i]["duetime"]) + " " + "minutes." + "\n"
i = i + 1
It would allow you to pick one data at a time and proceed.
Lets say that info["results"] is a list of length 2, then you could do:
>> a = fetchtime(data)
>> next(a)
Route Number: 83 Due in 25 minutes.
>> next(a)
Route Number: 42 Due in 33 minutes.
>> next(a)
StopIteration Error
or simple do:
>> for each in a:
print(each)
Route Number: 83 Due in 25 minutes.
Route Number: 42 Due in 33 minutes.
# In case if there would be no results (list would be empty), iterating
# over "a" would result in:
>> for each in a:
print(each)
Sorry, there's no real time info for this stop!
import time
import random
c1_strength = 12
c1_skill = 22
c2_strength = 16
c2_skill = 12
Modifier_skill = int(c1_skill) - int(c2_skill)
print("The skill modifier equals:\n")
print (Modifier_skill)
time.sleep(0.5)
Modifier_strength = int(c2_strength) - int(c1_strength)
print("The strength modifier equals:\n")
print (Modifier_strength)
time.sleep(0.5)
Player_1 = (random.randint(1,6))
print("Player_1 has rolled a 6 sided dice and rolled a:\n")
print(Player_1)
Player_2 = (random.randint(1,6))
print("Player_2 has rolled a 6 sided dice and rolled a:\n")
print(Player_2)
while(Player_1) == (Player_2):
print("no changes will be made")
break
if (Player_1) > (Player_2):
p1_strength = int(c1_strength) + int(Modifier_strength)
print("Player_1's new strength is:\n")
print(p1_strength)
p1_skill = int(c1_skill) + int(Modifier_skill)
print("Player_1's new skill is:\n")
print(p1_skill)
p2_strength = int(c2_strength) - int(Modifier_strength)
print("Player_2's new strength is:\n")
print(p2_strength)
p2_skill = int(c2_skill) - int(Modifier_skill)
print("Player_2's new skill is:\n")
print(p2_skill)
if (Player_1) > (Player_2):
pl2_strength = int(c2_strength) + int(Modifier_strength)
print("Player_1's new strength is:\n")
print(pl2_strength)
pl2_skill = int(c2_skill) + int(Modifier_skill)
print("Player_1's new skill is:\n")
print(pl2_skill)
pl1_strength = int(c1_strength) - int(Modifier_strength)
print("Player_2's new strength is:\n")
print(pl1_strength)
pl1_skill = int(c1_skill) - int(Modifier_skill)
print("Player_2's new skill is:\n")
print(pl1_skill)
this is my code, not sure whats wrong but when run it keeps saying that p1 strength is not defined. Another strange thing is that sometimes the code will work once or twice but then the next part will create an error, then after somehow fixing that the first part breaks again
First of all I'm barely sure what is even going on. this is hideous python. the problem is that p1_strength is defined in the if block
if(Player_1 > Player_2):
p1_strength = int(c1_strength) + int(Modifier_strength)
if this block does not execute, i.e. if Player_1 <= Player_2, p1_strength will be undefined.
this can be fixed by initializing your variables in the top of your script with something for instance, 0
c1_strength = 12
c1_skill = 22
c2_strength = 16
c2_skill = 12
p1_strength = 0
pl2_strength = 0