Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Casey Huckel
Courses Plus Student 4,257 PointsHow do you print out a string function?
How do you print out a string function from a list of numbers, particularly I want to print out a list of numbers with 7s in the 10 place.
3 Answers
Chris Freeman
Treehouse Moderator 68,468 PointsTo output to a file called output.txt you can use the following construct:
with open("output.txt", 'w') as f:
for item in list_of_harshad_number:
f.write("{}\n".format(item))
This will write each item in the list list_of_harshad_number on a separate line in the file output.txt. You will need to define list_of_harshad_numbers
Casey Huckel
Courses Plus Student 4,257 PointsThe input is a list of integers, I can assure you that. The output...here, actually, I'll send you the assignment which you don't have to do but if you could help me with #2:
- The sum of the Harshad numbers in ‘Rumbers.txt’.
- An output file containing all the Harshad numbers with a ‘7’ in the tens place.
- The numbers that are Harshad, have a 7 in the second column and are evenly divisible by 41.
'Rumbers.txt' is the data set that we are importing from to find the Harshad numbers and so on...
Hope this helps...and thanks for your help I really appreciate it
Chris Freeman
Treehouse Moderator 68,468 PointsBTW, I am in Portland, Oregon, USA (7 hours behind you) so I'm off to bed. I'll be back on tomorrow.
Casey Huckel
Courses Plus Student 4,257 PointsOk I'm in New Jersey actually. I've got to go to a wedding tomorrow but I'll be back on Sunday
Chris Freeman
Treehouse Moderator 68,468 PointsInteresting. The email notification timestamps show your message as 7:36am Saturday. Maybe they are all on UTC time. Enjoy the wedding. Have a slice of cake for me!
Chris Freeman
Treehouse Moderator 68,468 PointsChris Freeman
Treehouse Moderator 68,468 PointsCan you clarify the input and output you are looking for? Is the input a list of integers or numbers as strings? is the output a list of the input values (a filtered list) or a single string of all of the filtered numbers?