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 months ago.
Improve this question
I want to convert a string to integer without rounding. For example
s = "99.7"
x = s(int(float(s))
Output:
99
But I want the output to be 99.7
I was thinking of just adding all the strings to a list and somehow converting the list to an integer but I am not sure how to do that or how to even do it individually.
Desired output:
x = '99.7'
z = int(x)
output:
99.7
An integer in python can not have a floating point. To show this you should use
float(x)
This will prevent any rounding.
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
a=("\nHello")
print(len(a))
The intended output is a new line with 5 printed but instead there is no new line and the length is coming out to be 6.
There is a new line printed, plus the 5 characters in 'Hello', that's 6 in total:
a = "\nHello"
print(a)
print("Total length is", len(a))
Output
<space>
Hello
Total length is 6
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 4 years ago.
Improve this question
I have a code like this.
print (' ', totalh, totalt, totalo)
and I want the integer of totalh to be 2 2 instead of 22 with a space in-between the integers. How do I go about doing it?
Convert it to a string which is an iterable and can be an argument to " ".join.
totalh = 22
print(" ".join(str(totalh)))
Output:
2 2
I suggest you this simple way: first convert totalh into a string with each digit being a character, then use " ".join() to insert a space between each digit:
totalh = 22
print(" ".join(str(totalh))) #2 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 7 years ago.
Improve this question
From:
25f207f28332c7da539dd2539230a7aad975f907a93d924b4b037abacde677f0f71f75cc250df2e4dd2be3e97a60f289
To:
0x7a60f289, 0xdd2be3e9, 0x250df2e4, 0xf71f75cc, 0xcde677f0, 0x4b037aba,
0xa93d924b, 0xd975f907, 0x9230a7aa, 0x539dd253, 0x8332c7da, 0x25f207f2
Just slice the string into chunks and reverse the order adding 0x with str.format:
s = "25f207f28332c7da539dd2539230a7aad975f907a93d924b4b037abacde677f0f71f75cc250df2e4dd2be3e97a60f289"
print(["0x{}".format(s[i-8:i]) for i in range(len(s), 0, -8) ])
['0x7a60f289', '0xdd2be3e9', '0x250df2e4', '0xf71f75cc', '0xcde677f0', '0x4b037aba', '0xa93d924b', '0xd975f907', '0x9230a7aa', '0x539dd253', '0x8332c7da', '0x25f207f2']
If you actually want decimals:
print([int("0x{}".format(s[i-8:i]),16) for i in range(len(s), 0, -8) ])
[2053173897, 3710641129, 621671140, 4146034124, 3454433264, 1258519226, 2839384651, 3648387335, 2452662186, 1402851923, 2201143258, 636618738]
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 7 years ago.
Improve this question
Two questions:
How to create a char+number random string. one char and 2 digit numbers
for example: U12 OR W82
How to create a random 5 digit number with no zero at the beginning: 02345 , 03243
1)
import random, string
"%c%02d" % (random.choice(string.uppercase), random.randint(0, 99))
2)
import random
random.randint(10000, 99999)