0

How to separate output strings with ~ symbol? for example ~12~13~14~15~8

4th Jun 2017, 5:25 PM
Chilllittle
Chilllittle - avatar
12 Antworten
+ 5
for(x=0;x<str.length();x++) cout<<" ~ "<<str[x]; this is c++.
4th Jun 2017, 5:39 PM
Umbe
Umbe - avatar
+ 2
okay thank you all😊
4th Jun 2017, 7:35 PM
Chilllittle
Chilllittle - avatar
+ 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~
4th Jun 2017, 5:32 PM
LordHill
LordHill - avatar
+ 1
Got it😄 thanks justin
5th Jun 2017, 12:46 AM
Chilllittle
Chilllittle - avatar
0
Dont want put them in list
4th Jun 2017, 11:52 PM
Chilllittle
Chilllittle - avatar
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="~")
4th Jun 2017, 11:58 PM
Chilllittle
Chilllittle - avatar
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="")
5th Jun 2017, 12:18 AM
LordHill
LordHill - avatar
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~
5th Jun 2017, 12:37 AM
Chilllittle
Chilllittle - avatar
0
Then how i remove the tail ~ at the end?
5th Jun 2017, 12:38 AM
Chilllittle
Chilllittle - avatar
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]
5th Jun 2017, 12:40 AM
LordHill
LordHill - avatar
0
No problem. Happy to help.. I like your code, keep it up!
5th Jun 2017, 12:46 AM
LordHill
LordHill - avatar
- 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☝🏻️☝🏻
4th Jun 2017, 11:51 PM
Chilllittle
Chilllittle - avatar