Quick actions

cmd+k|ctrl+k

Navigation

Languages

SequencevsIterationwithSolution

Snippet info

Language

Python

Visibility

public

Author

masterhun

Created

2023-09-13T16:47:43.76663Z

Updated

2023-09-13T17:40:26.031097Z



print("Sequence vs. Iteration")

print()

# Sequence 

print("This is sequence.")

# A
# Python built-in function ord() 
letter = "A"
value = ord(letter) 
print(f"The character {letter} is {value} in ASCII.")
# Output: 65

# B
# Python built-in function ord() 
letter = "B"
value = ord(letter) 
print(f"The character {letter} is {value} in ASCII.")
# Output: 66 

# C
# Python built-in function ord() 
letter = "C"
value = ord(letter) 
print(f"The character {letter} is {value} in ASCII.")
# Output: 67 

# 120
# Python built-in function chr()
value = 120
letter = chr(value)
print(f"The value {value} is {letter} in ASCII.")
# Output: _____ 
 
# 121
# Python built-in function chr()
value = 121
letter = chr(value)
print(f"The value {value} is {letter} in ASCII.")
# Output: x

# 122
# Python built-in function chr()
value = 122
letter = chr(value)
print(f"The value {value} is {letter} in ASCII.")
# Output: z 

print()

print()

# Iteration 

print("This is iteration.")

plaintext = "this is a secret"

ciphertext = ""

# This for loop converts plaintext into ciphertext.

for letter in plaintext:
    temp = 0     # integer variable
    # missing code block 
    temp = ord(letter)
    # missing block of code 
    ciphertext += str(temp) + " "
    
print("PLAINTEXT: " + plaintext)

print("CIPHERTEXT: " + ciphertext)


# THE END 
INFO