Answer:
- import random
-
- states = {
- "Alabama": "Montgomery",
- "California": "Sacramento",
- "Florida": "Tallahassee",
- "Hawaii": "Honolulu",
- "Indiana": "Indianapolis",
- "Michigan": "Lansing",
- "New York": "Albany",
- "Texas" : "Austin",
- "Utah" : "Salt Lake City",
- "Wisconsin": "Madison"
- }
-
- correct = 0
- wrong = 0
- round = 1
- while(round <= 5):
- current_state = random.choice(list(states))
- answer = input("What is the capital of " + current_state + ": ")
-
- if(answer == states[current_state]):
- correct += 1
- else:
- wrong += 1
-
- round += 1
-
- print("Correct answer: " + str(correct))
- print("Wrong answer: " + str(wrong))
Explanation:
The solution code is written in Python 3.
Line 3 -14
Create a dictionary of US States with capital as each of their corresponding value. Please note only ten sample states are chosen here.
Line 16 - 18
Create variables to track the number of correct and inaccurate response and also round counter.
Line 19 - 28
Set the while condition to enable user to play the quiz for five questions and use random.choice to randomly pick a state from the dictionary and prompt user to input the capital of selected stated.
If the answer matched with the capital value of the selected state, increment the correct counter by one. Otherwise the wrong counter will be incremented by one. Increment the round counter by one before proceed to next round.
Line 30 - 31
Print the number of correct responses and wrong responses.
Answer:
The hexadecimal equivalent of the encrypted A is C2
Explanation:
Given
Encrypted binary digit of A = 11000010
Required
Hexadecimal equivalent of the encrypted binary digit.
We start by grouping 11000010 in 4 bits
This is as follows;
1100 0010
The we write down the hexadecimal equivalent of each groupings
1100 is equivalent to 12 in hexadecimal
So, 1100 = 12 = C
0010 is represented by 2 in hexadecimal
So, 0010 = 2
Writing this result together; this gives
1100 0010 = C2
Going through the conversion process;
A is first converted to binary digits by shifting a point to the left
A => 11000010
11000010 is then converted to hexadecimal
11000010 = C2
Conclusively, the hexadecimal equivalent of the encrypted A is C2
import java.util.*;
public class myClass {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.print("Input a String: ");
String str = scan.nextLine();
System.out.print("Input an integer: ");
int num = scan.nextInt();
for(int i=str.length()-1; i>=0; i--) {
for(int j=0; j<num; j++) {
System.out.print(str.charAt(i));
}
}
}
}
Answer:
C
Explanation:
myCar::accelerate()
here :: operator is used to access the member function outside the class.
we are calling accelerate() function using class and ::