Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 98

Python Exercise Example 98

Python 100 Examples Python 100 Examples

**Problem:** Input a string from the keyboard, convert all lowercase letters to uppercase, then output and save it to a disk file "test".

**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 of the above example is:


please input a string:
runoob.com
RUNOOB.COM

Python 100 Examples Python 100 Examples