Q:

Using Python loops to generate text based on user input

The following script asks a user for information, stores the information as variables, and then creates a file that inserts the variables into various places within the text. The created file is an html web page that can then be run on my web server. The example shows 4 sets of variables and works well. However I would like to ask a user for the total number of required sets and then perform a loop that keeps asking for the same info (i.e. video number, description, folder name) until the total number is reached. For each iteration, I would like to generate select sections of the html text. I'm a Python noob so any help/feedback is greatly appreciated. Thanks in advance!
# The next 12 variables prompt the use for the label, description and folder names for 4 videos
Video1_Num = raw_input('Enter the number label for Video 1: ')
Video1_Desc = raw_input('Enter the description of Video 1: ')
Video1_Fold = raw_input('Enter the name of the folder where video 1 is stored: ')

Video2_Num = raw_input('Enter the number label for Video 2: ')
Video2_Desc = raw_input('Enter the description of Video 2: ')
Video2_Fold = raw_input('Enter the name of the folder where video 2 is stored: ')

Video3_Num = raw_input('Enter the number label for Video 3: ')
Video3_Desc = raw_input('Enter the description of Video 3: ')
Video3_Fold = raw_input('Enter the name of the folder where video 3 is stored: ')

Video4_Num = raw_input('Enter the number label for Video 4: ')
Video4_Desc = raw_input('Enter the description of Video 4: ')
Video4_Fold = raw_input('Enter the name of the folder where video 4 is stored: ')

# The next line opens up a file with an html extension
f = open('index123.html','w')

# The following will be written into the file
html_page = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.4.4.js" type="text/javascript" charset="utf-8">
</script>

<script type="text/javascript">
    $(document).ready(function() {
        $("span.prj-slide1").click(function(){
            $("#select_opt1").slideToggle('fast');
        }); 

    });
</script>

<script type="text/javascript">
    $(document).ready(function() {
        $("span.prj-slide2").click(function(){
            $("#select_opt2").slideToggle('fast');
        }); 

    });
</script>

<script type="text/javascript">
    $(document).ready(function() {
        $("span.prj-slide3").click(function(){
            $("#select_opt3").slideToggle('fast');
        }); 

    });
</script>

<script type="text/javascript">
    $(document).ready(function() {
        $("span.prj-slide4").click(function(){
            $("#select_opt4").slideToggle('fast');
        }); 

    });
</script>

<title>Demo</title>

</head>

<body>

<div id="header"><a href="index123.html"><img src="logo.png" width="390" height="60" border="0" /></a></div>
<div id="select_head">Select the video you wish to review:</div>
<div id="select_opt">
    <p><span class="prj-slide1"><a href="" onclick="return false;"><b>Video %s:</b>&emsp; %s</a></span></p>
        <div id="select_opt1" style="display: none;">
            <video width="320" height="240" controls>
            <source src="./%s/%s_1.mp4" type="video/mp4">
            Your browser does not support the video tag.
            </video>
        </div>
    <br></br>
    <p><span class="prj-slide2"><a href="" onclick="return false;"><b>Video %s:</b>&emsp; %s</a></span></p>
        <div id="select_opt2" style="display: none;">
            <video width="320" height="240" controls>
            <source src="./%s/%s_1.mp4" type="video/mp4">
            Your browser does not support the video tag.
            </video>
        </div>
    <br></br>   
    <p><span class="prj-slide3"><a href="" onclick="return false;"><b>Video %s:</b>&emsp; %s</a></span></p>
        <div id="select_opt3" style="display: none;">
            <video width="320" height="240" controls>
            <source src="./%s/%s_1.mp4" type="video/mp4">
            Your browser does not support the video tag.
            </video>
        </div>
    <br></br>
    <p><span class="prj-slide4"><a href="" onclick="return false;"><b>Video %s:</b>&emsp; %s</a></span></p>
        <div id="select_opt4" style="display: none;">
            <video width="320" height="240" controls>
            <source src="./%s/%s_1.mp4" type="video/mp4">
            Your browser does not support the video tag.
            </video>
        </div>
    <br></br>
</div>
</body>
</html>""" %(Video1_Num, Video1_Desc, Video1_Fold, Video1_Fold, Video2_Num, Video2_Desc, Video2_Fold, Video2_Fold, Video3_Num, Video3_Desc, Video3_Fold, Video3_Fold, Video4_Num, Video4_Desc, Video4_Fold, Video4_Fold)

#'html_page gets written into the file and is closed. I then manually copy the newly created file to my web server.
f.write(html_page)
f.close()

A:

You can use list of dict.
video_list=[]
Suppose u get a three values, num_val, desc_str and fold_num as input
Then a make a dict of video as video={'num': num_val,'desc':'desc_str','fold_num':fold_num}
Now, you can keep pushing it in video_list as given below and can access them as mentioned below. Imp Note: while inputting data, there may be need of casting as per the datatypes like int or string.
video_list =[]
Video_count =4
for n in range(Video_count):
    num_val= input('enter number...')
    desc_str= input('enter desc...')
    fold_num= input('enter fold...')
    video={'num': num_val,'desc':'desc_str','fold_num':fold_num}
    video_list.append(video)

you can access the element by index and element as below:
    video_list[index]['num_val']

where index is any number between 0 and len(video_list)-1 (both inclusive). 
num_val is the element of dict and it could be any one of num_val, desc_str and fold_num.

