1

I'm barely new to python and stumble upon a problem that I can't really find an answer to online so here I ask. I am trying to make a basic algorithm that calculates the mean of an ungrouped data

#List or array of ungrouped data
ungrouped_data = [1, 2, 3, 4]
summation = 0
mean = 0

#for loop to sum all the data and print it out
print("Ungrouped data: ")
for x in ungrouped_data:
    summation += x
    print(x, end=", ")

#Calculate the mean by dividing the summation of x to the total number of list
mean = summation/len(List)

#Print the mean result
print()
print(f"Mean = "+ str(mean))

I was trying to print the string "ungrouped data" along with the list of data in a single horizontal line.

Ungrouped data: 1, 2, 3, 4
Mean = 2.5

But was struggling to do it and ended up having this.

Ungrouped data:
1, 2, 3, 4
Mean = 2.5

The question is, how can I use two separate print() function to print a text in a single horizontal line

khelwood
  • 52,115
  • 13
  • 74
  • 94
  • 2
    `print("Ungrouped data: ", end="")`? You are already doing it here `print(x, end=", ")`. – Axe319 Apr 27 '21 at 15:42
  • It works, thank you! sorry for the inconvenience I am really new to python, yes I believe I did use the end=" " but didn't think through enough on how it works, again really appreciate it – Hizon Pastorpili Apr 27 '21 at 15:44

0 Answers0