Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed yesterday.
Improve this question
How can i make a chances like "0.0023" and etc.
I tried random.random but i figured something like this
GG = random.randint(1, 100)
if GG == 1:
global TO
TO += 1
with open("TheOnly.txt", "w") as f:
f.write(str(TO))
return 'THE_ONLY (1/100)'
elif GG < 20 and GG > 1:
return 'RARE'
else:
return 'BASIC'
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 days ago.
Improve this question
I have an autistic neighbour who counts words and sentences. For example he'll say a word like "River" and say it has 5 letters and lands on the right. I wrote a python program I was going to install it on his windows tablet. This is what I have my question is do you see anything that could be streamlined or changed to make it simpler?
def foo():
while True:
print("\nEnter a word or sentance to see if its")
print("even, odds and which side it lands on")
a = input("")
b = len(a) - a.count(' ')
print(b)
if (b % 2) == 0:
print("{0} is even\nTo the left ".format(a))
else:
print("{0} is odd\nTo the right ".format(a))
foo()
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
print(i)
if i % 3 == 0:
print("cot")
elif i%5 == 0:
print("cot")
the code will output number from 1 to 100 and if the number between 1 and 100 is % by 3 or 5 it will be replace with cot,but if the number is cot the number will be put again,without the :cot
If i understand you correctly, what you are trying to do is to change the number to cot if it's divisible by 3 or 5.
So if any of those restrictions is accomplish, you need to assign 'cot' to the variable.
Like this:
i = <some number>
if i%3 == 0:
i = "cot"
elif i%5 == 0:
i = "cot"
print(i)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Create a function that takes a number num and returns each place value in the number.
Eg num_split(-434) ➞ [-400, -30, -4], num_split[59]->[50,9]
Try this:
def num_split(num):
num = str(num)
num = [c for c in num]
num = num[::-1]
num_lis = []
f = 1
for i in range(len(num)):
num_lis.append(int(num[i])*f)
f *= 10
return num_lis
print(num_split(59))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Let's assume:
for a in range(10):
if a == 2 or a == 5:
print (how often this condition was True)
of course will be two, in my code i want to know when my condition be True , thanks
count = 0 # set a variable for counting
for a in range(10):
if a == 2 or a == 5: # for each entry that meets the condition
count += 1 # add 1 to count
print(count) # 2
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
def greater_less_equal_5(answer):
if ___ :
return 1
elif ___:
return -1
else:
return 0
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)
(On line 2, fill in the if statement to check if answer is greater than 5.
On line 4, fill in the elif so that the function outputs -1 if answer is less than 5.)
def greater_less_equal_5(answer):
if answer>5 :
return 1
elif answer<5:
return -1
else:
return 0
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)
Try this