Skip to main content

6.14) Exercise 13: Solution

"""
Challenge: File name generator (strings)
Make a program that generates file names for storing your data.
For example, you might want a file name that looks like this:
Sample_Ilkely_10oct2013_site1.dat
The program should ask the user to enter a location,
a date and a sample number and it will print out the file name.
"""
# ask the user to enter details
location=raw_input('Sample location?')
date=raw_input('Sample date?')
number=raw_input('Sample number?')
# Solution 1 concatenate strings
filename='Sample'+'_'+location+'_'+date+'_'+'site'+number+'.dat'
print filename
# Solution 2 with the join function.
filename='_'.join(['Sample',location,date,'site'+number])+'.dat'
print filename