0
How to separate output strings with ~ symbol? for example ~12~13~14~15~8
12 ответов
+ 5
for(x=0;x<str.length();x++)
cout<<" ~ "<<str[x];
this is c++.
+ 2
okay thank you all😊
+ 1
Maybe end="~"? ... Finishing your print statement with end="" puts your next print string on the same line.
print("12", end="~")
print("13", end="~")
print("14")
output:
12~13~14
for i in range(1,11):
print(i,end="~")
output:
1~2~3~4~5~6~7~8~9~10~
+ 1
Got it😄 thanks justin
0
Dont want put them in list
0
My code is like this:
num_list = input("Enter numbers *Separate by using commas:").split(",")
print("~~Output~~")
count_odd = count_even = total = total2 = 0
a1 = ""
a2 = ""
for a in num_list:
if float(a) >= 10:
a1 = a1 + str(a)
total += float(a)
value1 = total*1.5
else:
a2 = a2 + str(a)
total2 += float(a)
value2 = total2*2
odd = ""
even = ""
for i in num_list:
if float(i) % 2:
count_odd += 1
odd = odd + str(i)
else:
count_even += 1
even = even + str(i)
###Still something wrong here👇🏻👇🏻
print("Values >=10:", "~", a1, end="~")
print("Values < 10:", "~", a2, end="~")
0
num_list = input("Enter numbers *Separate by using commas:").split(",")
print("~~Output~~")
count_odd = count_even = total = total2 = 0
a1 = ""
a2 = ""
'''
Below, note the added ~ after your
numbers are added
'''
for a in num_list:
if float(a) >= 10:
a1 = a1 + str(a) + "~"
total += float(a)
value1 = total*1.5
else:
a2 = a2 + str(a) + "~"
total2 += float(a)
value2 = total2*2
odd = ""
even = ""
for i in num_list:
if float(i) % 2:
count_odd += 1
odd = odd + str(i)
else:
count_even += 1
even = even + str(i)
'''
The method above to add ~ after each
number results in ~ being at the end
of the the output. The next 2 lines
will remove that final ~
'''
a1=a1[:-1]
a2=a2 [:-1]
'''
Below I removed ~ from the end
function and added a print() to move
the second output to the next line
'''
print("Values >=10: ~" + a1, end="")
print()
print("Values < 10: ~" + a2, end="")
0
print("Values >=10:", "~" + a1, end="")
print()
print("Values < 10:", "~" + a2, end="")
print()
My output:
Values >=10: ~12~17~14~
Values < 10: ~8~9~5~
0
Then how i remove the tail ~ at the end?
0
Check the code again, I fixed that :) ..
Put this just above your output print functions at the bottom
a1=a1[:-1]
a2=a2 [:-1]
0
No problem. Happy to help.. I like your code, keep it up!
- 1
Write a python program by using for loop to accept input (numbers) into a list. The program will:
1. Calculate the total based on the following condition:
Values more than or equal 10, total each value by multiplying 1.5, otherwise total each value by multiplying 2.
2. Display the values for “Values>=10” and “Values<10”.
3. Find out the numbers for Even values and Odd values.
4. Display the values for “Even Values” and “Odd Values”.
Sample output:
Enter numbers *separate by commas:12,17,14,8,9,5
~~Output~~
Values >=10: ~12~17~14
Values < 10: ~8~9~5
I want something ☝🏻☝🏻like this☝🏻️☝🏻