Normal view

There are new articles available, click to refresh the page.
Before yesterdayRavichandran J

பைதானில் Data Types

  1. Numeric int float (decimal numbers) complex numbers
  2. Text( strings= collection of characters,no.,space,etc.,) denoted within quotes.
  3. Boolean
  4. None

Variable = Containers to hold the values
naming variables ( @,!, etc not to be used)
multiple assignments

Tuple

References

Constants
Formats of Constants(All Caps)

Solution for Exercises:

Create a variable named name and assign your name to it. Then print the value of the variable.

[24]
0s
name= "Ravi"
print(name)
Ravi
Create a variable age and assign your age to it. Later, reassign the variable with a new value and print the new value.

[25]
0s
Age=62
Age=32
print(Age)
32
Assign the values 5, 10, and 15 to three variables a, b, and c in a single line.Print their values.

[26]
0s
a,b,c=5,10,15
print(a,b,c)
5 10 15
Swap the values of two variables x and y without using a third variable. Print their values before and after swapping.

[28]
0s
x,y=5,10
print(x,y)
x,y,=y,x
print(x,y)
5 10
10 5
[29]
0s
x,y=5,10
print(x,y)
x=x+y
y=x-y
x=x-y
print(x,y)
5 10
10 5
[30]
0s
PI=22/7
print(PI)
3.142857142857143
Constant is a static variable.

[31]
0s
PI=22/7
r=10
Area=PI*r*r
print(Area)
314.2857142857143
Define constants for the length and width of a rectangle.

[33]
0s
LEN=4
BRTH=5
A=LEN*BRTH
print(A)

20
Define a constant for π (pi) and a variable for the radius. Calculate and print the circumference of the circle.

[36]
0s
PI=22/7
r=10
C=PI*r+r
print(C)
41.42857142857143
[37]
0s
PI=22/7
r=10
C=PI*(r+r)
print(C)
62.857142857142854

பைதானில் Data Types

  1. Numeric int float (decimal numbers) complex numbers
  2. Text( strings= collection of characters,no.,space,etc.,) denoted within quotes.
  3. Boolean
  4. None

Variable = Containers to hold the values
naming variables ( @,!, etc not to be used)
multiple assignments

Tuple

References

Constants
Formats of Constants(All Caps)

Solution for Exercises:

Create a variable named name and assign your name to it. Then print the value of the variable.

[24]
0s
name= "Ravi"
print(name)
Ravi
Create a variable age and assign your age to it. Later, reassign the variable with a new value and print the new value.

[25]
0s
Age=62
Age=32
print(Age)
32
Assign the values 5, 10, and 15 to three variables a, b, and c in a single line.Print their values.

[26]
0s
a,b,c=5,10,15
print(a,b,c)
5 10 15
Swap the values of two variables x and y without using a third variable. Print their values before and after swapping.

[28]
0s
x,y=5,10
print(x,y)
x,y,=y,x
print(x,y)
5 10
10 5
[29]
0s
x,y=5,10
print(x,y)
x=x+y
y=x-y
x=x-y
print(x,y)
5 10
10 5
[30]
0s
PI=22/7
print(PI)
3.142857142857143
Constant is a static variable.

[31]
0s
PI=22/7
r=10
Area=PI*r*r
print(Area)
314.2857142857143
Define constants for the length and width of a rectangle.

[33]
0s
LEN=4
BRTH=5
A=LEN*BRTH
print(A)

20
Define a constant for π (pi) and a variable for the radius. Calculate and print the circumference of the circle.

[36]
0s
PI=22/7
r=10
C=PI*r+r
print(C)
41.42857142857143
[37]
0s
PI=22/7
r=10
C=PI*(r+r)
print(C)
62.857142857142854

பைதானில் Data Types

*Data Types:
*

  1. Numeric int float (decimal numbers) complex numbers
  2. Text( strings= collection of characters,no.,space,etc.,) denoted within quotes.
  3. Boolean

  4. None

Variables and Constants:

Variable = Containers to hold the values
naming variables ( @,!, etc not to be used)
multiple assignments

Tuple

References

Constants (Statice variable)
Formats of Constants(All Caps)

Solution for Exercises:

Create a variable named name and assign your name to it. Then print the value of the variable.

[24]
0s
name= "Ravi"
print(name)
Ravi
Create a variable age and assign your age to it. Later, reassign the variable with a new value and print the new value.

[25]
0s
Age=62
Age=32
print(Age)
32
Assign the values 5, 10, and 15 to three variables a, b, and c in a single line.Print their values.

[26]
0s
a,b,c=5,10,15
print(a,b,c)
5 10 15
Swap the values of two variables x and y without using a third variable. Print their values before and after swapping.

[28]
0s
x,y=5,10
print(x,y)
x,y,=y,x
print(x,y)
5 10
10 5
[29]
0s
x,y=5,10
print(x,y)
x=x+y
y=x-y
x=x-y
print(x,y)
5 10
10 5
[30]
0s
PI=22/7
print(PI)
3.142857142857143
Constant is a static variable.

[31]
0s
PI=22/7
r=10
Area=PI*r*r
print(Area)
314.2857142857143
Define constants for the length and width of a rectangle.

[33]
0s
LEN=4
BRTH=5
A=LEN*BRTH
print(A)

20
Define a constant for π (pi) and a variable for the radius. Calculate and print the circumference of the circle.

[36]
0s
PI=22/7
r=10
C=PI*r+r
print(C)
41.42857142857143
[37]
0s
PI=22/7
r=10
C=PI*(r+r)
print(C)
62.857142857142854

பைதானில் முதல் பாடம்

8/7/2024,சென்னை

பைதான் வகுப்பு இன்று ஆரம்பம்.

அறிமுக உரை கேட்டேன்.
Google Colab ல் print command கொடுத்து சோதனை செய்தேன்.
பைதான் கணினியில் நிறுவப்பட்டது.
IDE ஆக PyCharm யினை install செய்துள்ளேன். வகுப்பில் ஆசிரியர் VS பயன்படுத்துவதாக கூறினார்.எனவே, PyCharm எந்த அளவிற்கு உபயோகப்படும் எனத் தெரியவில்லை....பார்ப்போம்.

javascript functions

My js file is given below:
var pos = 0;
var board = document.getElementById('board');
var status = document.getElementById('status');
var questn, choice, A, B, C, D, cor = 0;
var questions = [
["Shortcut of copy", "CTRL+A", "CTRL+S", "CTRL+C", "CTRL+Z", "C"],
["10+10", "20", "30", "40", "50", "A"],
["10+20", "20", "30", "40", "50", "B"],
["10+30", "20", "30", "40", "50", "C"]
];
var incorrectAnswers = [];

function DisplayQuestion() {
board.innerHTML = "";
status.innerHTML = "Question " + (pos + 1) + " of " + questions.length;
questn = questions[pos][0];
A = questions[pos][1];
B = questions[pos][2];
C = questions[pos][3];
D = questions[pos][4];
board.innerHTML += "

" + questn + "

";
board.innerHTML += "" + A + "
";
board.innerHTML += "" + B + "
";
board.innerHTML += "" + C + "
";
board.innerHTML += "" + D + "
";
board.innerHTML += "Submit Answer";
}

function checkAnswer() {
var choice;
var choices = document.getElementsByName("choices");
var choiceSelected = false;
for (var i = 0; i < choices.length; i++) {
if (choices[i].checked) {
choice = choices[i].value;
choiceSelected = true;
break;
}
}
if (!choiceSelected) {
alert("Please select an answer before submitting.");
return;
} else {
var correctAnswer = questions[pos][5];

    if (choice === correctAnswer) {
        cor++;
    } else {
        incorrectAnswers.push({ 
            questionIndex: pos, 
            userChoice: { letter: choice, value: questions[pos][parseInt(choice, 10)] }, 
            correctAnswer: { letter: correctAnswer, value: questions[pos][parseInt(correctAnswer, 10)] } 
        });
    }
    pos++;
    if (pos >= questions.length) {
        DisplayResult();
    } else {
        DisplayQuestion();
    }
}

}

function DisplayResult() {
board.innerHTML = "

You got " + cor + " questions out of " + questions.length + "

";
status.innerHTML = "Quiz completed";

for (var i = 0; i < incorrectAnswers.length; i++) {
var questionIndex = incorrectAnswers[i].questionIndex;
var userChoice = incorrectAnswers[i].userChoice;
var correctAnswer = incorrectAnswers[i].correctAnswer;

board.innerHTML += "<h3>Question: " + questions[questionIndex][0] + "</h3>";
board.innerHTML += "Your Answer: " + userChoice.letter + " (" + userChoice.value + ")" + "<br>";
board.innerHTML += "Correct Answer: " + correctAnswer.letter + " (" + correctAnswer.value + ")" + "<br><br>";

}
}

The DisplayResult function works wrongly. It gives output as :
You got 2 questions out of 4
Question: Shortcut of copy
Your Answer: A (undefined)
Correct Answer: C (undefined)

Question: 10+20
Your Answer: C (undefined)
Correct Answer: B (undefined).

I want to have the actual values of user's choice and correct answer, instead of displaying Option values.
Please help.

❌
❌