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)
Related
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'
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
For example, if the number 34560 is entered, then it has 3 even numbers (4, 6 and 0) and 2 odd numbers (3 and 5).
for num in int(len(number)):
if num % 2 != 0:
print(num, end=" ")```
you can use for example like this:
number = 34560
even = [int(x) for x in str(number) if int(x)%2 == 0]
odd = [int(x) for x in str(number) if int(x)%2 != 0]
print(even)
print(odd)
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
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 8 years ago.
Improve this question
what I'm trying to do is to print the numbers 2-100 and mark the prime numbers with -
So, this should be the output:
2-
3-
4
5-
6
7-
8
9
10
.
.
.
100
Try this code:
primes = []
for candidate in range(2, 101):
can_be_prime = True
for prime in primes:
if candidate % prime == 0:
can_be_prime = False
break
if can_be_prime:
primes.append(candidate)
print "%d-" % candidate
else:
print candidate