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 2 years ago.
Improve this question
I have this code for i in range(1111111111111111, 9999999999999999): print(i)
I want to give an input which user will select how much value will the program generate.
like if he want only to generate 5k numbers it will only generate 5k.
what to do!
You can do it like this:
a = 1111
b = 9999
num = 500 # how many values you want
for i in range(a, b):
if i >= a + num:
break
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 5 days ago.
Improve this question
I want to give the values in all_X_H in there normal indices order a to variables in ring[corrector_indexes[m]].KickAngle which doesn't have the same order as a.
This is a simple example:
all_X_H = [
0,-0.000009
1,-0.000018
2,-0.000010
3,-0.000007]
corrector_indexes = [1,2,3,4]
final_corr_order_H = [3,2,1,0]
for m in final_corr_order_H:
for a in range(len(all_X_H)):
ring[corrector_indexes[m]].KickAngle = [all_X_H[a],0]
The result i want to see is
ring[corrector_indexes[3]].KickAngle = [all_X_H[0],0]
ring[corrector_indexes[2]].KickAngle = [all_X_H[1],0]
ring[corrector_indexes[1]].KickAngle = [all_X_H[2],0]
ring[corrector_indexes[0]].KickAngle = [all_X_H[3],0]
How can i define two different indices in one for loop to implement 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 4 months ago.
Improve this question
How can I multiply two elements in a list?
I am reading a text file, and printing the following:
for i in range(len(listeisotoper)):
print("Isotop type:"+listeisotoper[i][0])
print("Isotopisk masse u: "+listeisotoper[i][1])
print("Naturlig forekomst: "+listeisotoper[i][2])
print("xxx"+"g/mol")
print("\n")
However i cannot fathom how i can multiply the listeisotoper[i][1] * listeisotoper[i][2]
and then have it print the number with decimal points.
Any suggestions?
It isn't clear question for me, but may be this code will help you
for i in range(len(listeisotoper)):
print("Isotop type:"+listeisotoper[i][0])
print("Isotopisk masse u: "+listeisotoper[i][1])
print("Naturlig forekomst: "+listeisotoper[i][2])
mult_res = float(listeisotoper[i][1]) * float(listeisotoper[i][2])
print(f"Mult = {mult_res:.1f}")
print("xxx"+"g/mol")
print("\n")
I am assuming your problem is multiplying strings. If so, try this:
for i in range(len(listeisotoper)):
print("Isotop type:"+listeisotoper[i][0])
print("Isotopisk masse u: "+listeisotoper[i][1])
print("Naturlig forekomst: "+listeisotoper[i][2])
print(str(float(listeisotoper[i][1])*float(listeisotoper[i][2]))+"g/mol")
print("\n")
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 4 months ago.
Improve this question
Essentially, I was wondering if you could merge these 2 lines:
items = ["cat","apple","taco"]
def change(x):
return(items[x-1])
temp = change(2) # THIS ONE AND
temp = "orange" # THIS ONE
It's difficult for me to explain, my apologies. I essentially just want to be able to get rid of that temp variable or a least only have to use it once.
Why not just something like:
items = ["cat","apple","taco"]
def change(ind, tx):
items[ind-1] = tx
change(2, "orange")
print(items)
# >>> ['cat', 'orange', 'taco']
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'd like to know how I can use a string like order = '8927391' (with 8 being largest and 1 being smallest) and print out an answer according to the order, for example:
Let's say if_no_is_higher(no1, no2) is a function that I have defined already to print yes if the first number is higher than the second, and no if the first number is smaller.
if_no_is_higher(8, 9)
returns
yes
because according to the order 8 is higher than 9
Create a custom order and use the index of that collection to check for your condition:
a = '8927391'
custom_order = [int(item) for item in a]
min(8, 9, key=custom_order.index)
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 6 years ago.
Improve this question
I need to display the column index as alphabet in my program, like, c3, instead of 2,3 [ a is 0, hence c would be 2]
If you're only interested in the 26 lower case characters, this would work:
alph = 'abcdefghijklmnopqrstuvwxyz'
startIndex = (2,3)
endIndex = (alph[startIndex[0]], startIndex[1])
print(endIndex[0] + str(endIndex[1]))