Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-pointers/lab_adaptive.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (22 sloc)
532 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def main(): | |
size = 0 | |
# get the size | |
while size <= 0: | |
try: | |
size = int(input('Enter a size ')) | |
if size <= 0: | |
print('Not a valid size') | |
except ValueError: | |
print('Not an integer') | |
print('Reading in',size,'values') | |
# create a list of the right size | |
values = [None]*size | |
# get the values | |
for i in range(size): | |
values[i] = input('Enter a value ') | |
# print everything in reverse | |
for i in range(size-1,-1,-1): | |
print('Element',i,'is',values[i]) | |
if __name__ == '__main__': | |
sys.exit( main() ) |