Add additional versions of conditional_expressions test

This commit is contained in:
Michael Hansen
2022-04-26 13:11:40 -07:00
parent b0fa45840f
commit 4884b5447f
4 changed files with 74 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,44 @@
import sys
a = 1
result = 'even' if a % 2 == 0 else 'odd'
print result
# odd
a = 2
result = 'even' if a % 2 == 0 else 'odd'
print result
# even
a = 1
result = a * 2 if a % 2 == 0 else a * 3
print result
# 3
a = 2
result = a * 2 if a % 2 == 0 else a * 3
print result
# 4
a = 1
sys.stdout.write('even\n') if a % 2 == 0 else sys.stdout.write('odd\n')
# odd
a = 1
if a % 2 == 0:
print 'even'
else:
print 'odd'
# odd
a = -2
result = 'negative and even' if a < 0 and a % 2 == 0 else 'positive or odd'
print result
# negative and even
a = -1
result = 'negative and even' if a < 0 and a % 2 == 0 else 'positive or odd'
print result
# positive or odd

View File

@@ -0,0 +1,30 @@
import sys <EOL>
a = 1 <EOL>
result = 'even' if a % 2 == 0 else 'odd' <EOL>
print result <EOL>
a = 2 <EOL>
result = 'even' if a % 2 == 0 else 'odd' <EOL>
print result <EOL>
a = 1 <EOL>
result = a * 2 if a % 2 == 0 else a * 3 <EOL>
print result <EOL>
a = 2 <EOL>
result = a * 2 if a % 2 == 0 else a * 3 <EOL>
print result <EOL>
a = 1 <EOL>
sys . stdout . write ( 'even\n' ) if a % 2 == 0 else sys . stdout . write ( 'odd\n' ) <EOL>
a = 1 <EOL>
if a % 2 == 0 : <EOL>
<INDENT>
print 'even' <EOL>
<OUTDENT>
else : <EOL>
<INDENT>
print 'odd' <EOL>
<OUTDENT>
a = - 2 <EOL>
result = 'negative and even' if a < 0 and a % 2 == 0 else 'positive or odd' <EOL>
print result <EOL>
a = - 1 <EOL>
result = 'negative and even' if a < 0 and a % 2 == 0 else 'positive or odd' <EOL>
print result <EOL>