SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
Functions Strings And Objects
Exercise:
Programming Excercises
Question:7 | ISBN:978013274719 | Edition: 6

Question

(Random character) Write a program that displays a random uppercase letter using the time.time() function.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program Code:

import random
import time

# Get the current time in seconds since the epoch
currentTime = int(time.time())

# Set the seed for the random number generator
random.seed(currentTime)

# Generate a random ASCII value for an uppercase letter (65 to 90)
randomASCII = random.randint(65, 90)

# Convert the ASCII value to a character
randomCharacter = chr(randomASCII)

# Display the random uppercase letter
print("Random Uppercase Letter:", randomCharacter)

 

Executed Output 1:

Random Uppercase Letter: I

Executed Output 2:

Random Uppercase Letter: G

 

0 0

Discussions

Post the discussion to improve the above solution.