26.4k views
2 votes
Write a program that uses a loop to print the uppercase alphabet with the correct ASCII number next to each letter. (E.g. one line might be A 65)

User Cjay
by
5.6k points

2 Answers

3 votes

Answer:

The program to this question can be given as:

Program:

# define variable x and assign value #

x1 = 64

#define loop

while x1 >= 64 and x1 <= 89:

x1 =x1+ 1

print(str(chr (x1))+ " ASCII number is = " + str(x1)))

#print value #

Output:

A ASCII number is =65

B ASCII number is =66

C ASCII number is =67

D ASCII number is =68

E ASCII number is =69

F ASCII number is =70

G ASCII number is =71

H ASCII number is =72

I ASCII number is =73

J ASCII number is =74

K ASCII number is =75

L ASCII number is =76

M ASCII number is =77

N ASCII number is =78

O ASCII number is =79

P ASCII number is =80

Q ASCII number is =81

R ASCII number is =82

S ASCII number is =83

T ASCII number is =84

U ASCII number is =85

V ASCII number is =86

W ASCII number is =87

X ASCII number is =88

Y ASCII number is =89

Z ASCII number is =90

Step-by-step explanation:

In the above python program firstly we define a variable that is "x1" in this variable we assign a value that is 64. Then we define a while loop In this loop we increment the value of x1 by 1 and print the alphabet in uppercase and its ASCII number.

For print this output we use the str() function and chr () function. The str() function prints the ASCII number and In the str()function we use chr () function that converts the number into character.

User Armada
by
6.0k points
6 votes

Answer:

function printAlphabet()

{

for(l="A".charCodeAt(0); String.fromCharCode(l) <= 'Z'; l++)

{ document.getElementById('output').innerText+=String.fromCharCode(l)+" " + l + "\\"; }

alert('OK');

}

Step-by-step explanation:

This Javascript function will loop from the value of 'A' (65) to the value of 'Z' (90) included.

No need to know the ASCII number of neither 'A' nor 'Z', since this is handled by the JavaScript function charCodeAt and fromCharCode. The code would have been simpler if

It will output the result in a DIV with the id 'output'.

You can see the output in the attached file.

Write a program that uses a loop to print the uppercase alphabet with the correct-example-1
User Muhammad Aqib
by
5.8k points