+ 1
How to insert randomint inside a string
For example I have a string that consists of 10 random integers, and through input I want to Cross out one of them (it becomes “—“ instead of “number” Was: “1,40,33,10,34,90,91....” Which one do want to cross out? : 34 Became: “1,40,33,10,—,90,91...”
11 Answers
+ 5
Here is the code:
s = "1, 40, 33, 10, 34, 90..."
num = input('Your number: ")
if(num in s):
s = s.replace(num, "--")
+ 1
I still don't understand your question very well, you want to change number 34 with a randint generated number ?
+ 1
This is what I understood:
You have a string, say s = "1,40,33,10..."
Let's say user input is 40
The string should become: "1,--,33,10..." ?
+ 1
If you are working with strings, you should use the .choice() function from random module to pick a random character from a set of string
+ 1
Aymane Boukrouh thank you!
+ 1
Oscar anytime!
0
Aymane Boukrouh , no. i want to change the number a user inputs with a string “—“
sort of like when cross out numbers in lottery
0
My point is, why use a string ? Can't you use a list ?
0
no because i have an assignment that says i HAVE to use a string...
0
Aymane Boukrouh and yes, you understood exactly right
0
One line code
https://code.sololearn.com/c7P6rdOquDa7/?ref=app