Tute 6

.docx

School

Royal Melbourne Institute of Technology *

*We aren’t endorsed by this school

Course

108

Subject

Mechanical Engineering

Date

Apr 3, 2024

Type

docx

Pages

5

Uploaded by tadeleguma

Report
VIT1102 - Introduction to Programming VU College Tutorial 6 – Strings and Text Files Run commands below in PyCharm Console Ex1 Run code given in Topic 6 lecture note slides 3, 4, 5, 6, 7, 8, 9, 10, 11 and 12 in Python console. Ex2 a. Find the length of myString using a command. b. Write a command to display the first letter (‘T’) of myString. c. Write a command to display the last letter (the ! mark) of myString. d. Try command myString[:5]. e. Display myString 4 times. f. Write a command to display sub-string ‘on the mat!’ g. Write commands to display a list with elements ['The', 'cat', 'sat', 'on', 'the', 'mat!'] Task 1 – File Writing Open PyCharm and Create a Project called Tutoral6. In Tutorial6 create a Python package task1. Create Python files for each of the exercises below. Ex1 Enter and run Example 1 of lecture Topic 6. Ex2 Enter and run Example 2 of lecture Topic 6. 1 VIT1102 – Tutorial 6.docx Oshadi Alahakoon 2016
VIT1102 - Introduction to Programming VU College Ex3 – Read this question completely and carefully before you start implementing. Read red colour comments describing the code. Add a new Python file Ex3.py to package task1. Enter and run the code below. When you run the program it will look as follows. Answer the questions below and show your teacher. 1. Add a docString to above code describing its functionality. 2. Locate the file student.txt. In your DocString describe where the file is saved. Eg: File is saved in G:\VIT1102\Projects\Tutorials 3. Each time you run your code, the previous record will get overwritten. Change your code to append new records to the existing records in the text file. 4. Once you make the above change and run the program for several times your text file contents should look similar to the following screen print. 2 VIT1102 – Tutorial 6.docx Oshadi Alahakoon 2016
VIT1102 - Introduction to Programming VU College 5. Change your code to add appropriate formatting to your file, so that it looks as follows. Make sure you also change the name of the formatted file to student1.txt. 6. Add up to 10 records to your text file. Note : At the completion of the exercise you should have 2 text files. Task 2 – File Reading In project Tutorial6 create a Python package task2. Ex1 Enter and run file read example using a ‘ for ’ loop (Example 3) of lecture Topic 6. You may use your student1.txt file as the input file. Additional Exercises a. Write a Python program to read a string and count the number of digits in it. The output of your code should look as follows. 3 VIT1102 – Tutorial 6.docx Oshadi Alahakoon 2016
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help