Quick actions

cmd+k|ctrl+k

Navigation

Languages

SequencevsIterationwithoutSolution

Snippet info

Language

Python

Visibility

public

Author

masterhun

Created

2023-09-13T17:26:35.379628Z

Updated

2023-09-13T21:07:02.140056Z



print("Sequence vs. Iteration")

print()

# Sequence 

print("This is sequence.")

# A
# Python built-in function ord() 
letter = "A"
value = ord(letter)     # ord("A") takes a character/letter and returns an integer value. 
print(f"The character {letter} is {value} in ASCII.")
# Output: 65

# B
# Python built-in function ord() 
letter = "B"
value = ord(letter)     # ord("B") takes a character/letter and returns an integer value. 
print(f"The character {letter} is {value} in ASCII.")
# Output: 66 

# C
# Python built-in function ord() 
letter = "C"
value = ord(letter)     # ord("C") takes a character/letter and returns an integer value. 
print(f"The character {letter} is {value} in ASCII.")
# Output: 67 

# 120
# Python built-in function chr()
value = 120
letter = chr(value)     # chr(120) takes an integer value and returns a letter/character. 
print(f"The value {value} is {letter} in ASCII.")
# Output: x
 
# 121
# Python built-in function chr()
value = 121
letter = chr(value)     # chr(121) takes an integer value and returns a letter/character. 
print(f"The value {value} is {letter} in ASCII.")
# Output: y

# 122
# Python built-in function chr()
value = 122
letter = chr(value)     # chr(122) takes an integer value and returns a letter/character. 
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 
    # 
    # missing block of code 
    ciphertext += str(temp) + " "
    
print("PLAINTEXT: " + plaintext)

print("CIPHERTEXT: " + ciphertext)


# THE END 
INFO