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 months ago.
Improve this question
counttonum = 1
countnum = input("[•] Provide A Number :")
while counttonum < countnum:
print("[", counttonum, "] : Number = ", counttonum)
counttonum +=1
I was trying to make a counting tool that counts up to the provided number from the “input()” function.
For example:
providedNumberFromInput = 5
output = 1
2
3
4
5
And it’ll stop if the provided number is reached. Please help me.
You are very close to solution. Problem is that input() returns value as string so you will need to convert it. And also if you want to include entered number use <= instead of <
while counttonum <= int(countnum):
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
How to select the previous number in list comprehension that starts from the second one?
The formula is [w(j-1)* 5 +w for t in y]?
w(j-1) is the first number in list.
Not exactly sure what you are trying to achieve. Therefore, my own interpretation of the problem. Assume you have a list of numbers:
my_list = range(1, 10)
Now we want to iterate over this list starting from the second entry and also access the previous entry:
new_list = [my_list[i - 1]*5 + my_list[i] for i, n in enumerate(my_list) if i > 0]
print(new_list)
This way you can get access to a list element and its predecessor.
Is this what you are trying to achieve?
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
Need some help here
num = [(1,4,5,30,33,41,52),(2,10,11,29,30,36,47),(3,15,25,37,38,58,59)]
if the last 6 digits are located to return the first digit.
example if finds 10,11,29,30,36,47 return 2
You can use next similair to user's approach:
num = [(1,4,5,30,33,41,52),(2,10,11,29,30,36,47),(3,15,25,37,38,58,59)]
to_find = [10,11,29,30,36,47]
print(next(n for n, *nums in num if nums == to_find))
2
You can use next with a conditional generator expression:
num = [(1,4,5,30,33,41,52),(2,10,11,29,30,36,47),(3,15,25,37,38,58,59)]
search = 11
next(first for first, *rest in num if search in rest)
# 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 3 years ago.
Improve this question
I am using python3,
I want to add 50 to second and third elements in the list below.
list_ = [0,0,0,0,0]
desiredlist = [0,50,50,0,0]
Can you help me?
Thanks in advance.
Here you go:
add_to_elements = [1, 2]
for i in range(len(list_)):
if i in add_to_elements:
list_[i] += 50
Whats wrong with doing this?
list[1] += 50
list[2] += 50
If you know the index value then you can use insert function
insert takes argument as index and value EX: insert(index,value)
list_ = [0,0,0,0,0]
list_.insert(1,50)
list_.insert(2,50)
type the index you want to change and assign the new value:
list_[1] = 50
list_[2] = 50
note: top of list starts with zero
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
I have a list composed of integers, and I would like to do this :
freeSushi = max(sushiPrices <= sushiPrice)
sushiPrice being an integer and sushiPrices being a list.
Any idea of how I can do this ?
You can use filter before applying max
max(filter(lambda price: price <= sushiPrice, sushiPrices)
This would work, if "something" was a list of prices less than or equal to sushiPrice:
freeSushi = max(something)
So how can we create a list of prices less than sushiPrice? Comprehend?
Use a for loop like so:
for i in sushiPrices:
if i > sushiPrice:
del sushiPrices[sushiPrices.index(i)]
freeSushi = max(sushiPrices)