Python Exercise Example 98
Question:Input a string from the keyboard, convert all lowercase letters to uppercase letters, then output it to a disk file "test" for storage.
Program analysis:None.
Program source code:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
if __name__ == '__main__':
fp = open('test.txt','w')
string = raw_input('please input a string:\n')
string = string.upper()
fp.write(string)
fp = open('test.txt','r')
print fp.read()
fp.close()
The output result of the above example is:
please input a string: example.com example.comOther extensions
Python 100 Examples