Skip to content

Commit 9ca512d

Browse files
authored
Merge pull request mjhea0#13 from Ivoah/master
Change all python code to python 3
2 parents b2fcd6f + cda4fcb commit 9ca512d

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

guess.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
number = random.randint(1, 20)
55
guesses = 0
66

7-
print 'Hello! What is your name?'
8-
name = raw_input()
7+
print('Hello! What is your name?')
8+
name = input()
99

10-
print "Hi, {}. I'm thinking of a number from 1 and 20.".format(name)
10+
print("Hi, {}. I'm thinking of a number from 1 and 20.".format(name))
1111

1212
while guesses < 6:
1313

14-
print 'What is your guess. You have {} more guesses.'.format(6-guesses)
15-
guess = raw_input()
14+
print('What is your guess. You have {} more guesses.'.format(6-guesses))
15+
guess = input()
1616
guess = int(guess)
1717

1818
guesses = guesses + 1
1919

2020
if guess < number:
21-
print 'Too low.'
21+
print('Too low.')
2222
elif guess > number:
23-
print 'Too high.'
23+
print('Too high.')
2424
elif guess == number:
25-
print 'Good job, {}! You guessed my number in {} guesses!'.format(name,guesses)
25+
print('Good job, {}! You guessed my number in {} guesses!'.format(name,guesses))
2626
break
2727

2828
if guess != number:
29-
print 'Nope. The number I was thinking of was {}.'.format(number)
29+
print('Nope. The number I was thinking of was {}.'.format(number))

readme.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ What do I mean by dynamic? Well, with a dynamically typed language you can do th
99
```sh
1010
>>> variable = 1
1111
>>> type(variable)
12-
<type 'int'>
12+
<class 'int'>
1313
>>> variable = "Foo"
1414
>>> type(variable)
15-
<type 'str'>
15+
<class 'str'>
1616
>>> variable = ["bar",10]
1717
>>> type(variable)
18-
<type 'list'>
18+
<class 'list'>
1919
```
2020

2121
Essentially, you can change the datatype (from an integer to a string to a list, in the above example) at any point in a program. In a statically typed language, this would result in an error when compiled.
@@ -191,7 +191,7 @@ Ruby has a bigger web presence with Rails than Python does with Django, so if yo
191191
That said, take a look at the two code snippets below -
192192

193193
```python
194-
print "Hello, World!"
194+
print("Hello, World!")
195195
```
196196

197197
and
@@ -242,34 +242,34 @@ Guessing game ...
242242

243243
```python
244244
import random
245-
import os
245+
246246

247247
number = random.randint(1, 20)
248248
guesses = 0
249249

250-
print 'Hello! What is your name?'
251-
name = raw_input()
250+
print('Hello! What is your name?')
251+
name = input()
252252

253-
print "Hi, {}. I'm thinking of a number from 1 and 20.".format(name)
253+
print("Hi, {}. I'm thinking of a number from 1 and 20.".format(name))
254254

255255
while guesses < 6:
256256

257-
print 'What is your guess. You have {} more guesses.'.format(6-guesses)
258-
guess = raw_input()
257+
print('What is your guess. You have {} more guesses.'.format(6-guesses))
258+
guess = input()
259259
guess = int(guess)
260260

261261
guesses = guesses + 1
262262

263263
if guess < number:
264-
print 'Too low.'
264+
print('Too low.')
265265
elif guess > number:
266-
print 'Too high.'
266+
print('Too high.')
267267
elif guess == number:
268-
print 'Good job, {}! You guessed my number in {} guesses!'.format(name,guesses)
268+
print('Good job, {}! You guessed my number in {} guesses!'.format(name,guesses))
269269
break
270270

271271
if guess != number:
272-
print 'Nope. The number I was thinking of was {}.'.format(number)
272+
print('Nope. The number I was thinking of was {}.'.format(number))
273273
```
274274

275275
#### Ruby

0 commit comments

Comments
 (0)