How to Add the Answers

How to add Multiple Choice Questions with Correct Answers in Google Quiz

Currently you are comparing the index op against the answer key in column D.

What you need to do instead is to evaluate the entries in columns P to Z corresponding to the index op against TRUE or FALSE

To do this you can modify your code as following:

function makeMultipleCQ(d, form){
var mcItem = form.addMultipleChoiceItem();
mcItem.setTitle(d[1]);
mcItem.setTitle(d[1]);
if(d[2] !== "N"){mcItem.setPoints(d[2])};
if(d[4] === "Y"){mcItem.setRequired(true);}

//Filter blank cells
var options = d.splice(5,10);
var options = options.filter(function(x){return x !== ""});
//after the previos splice the original array and consequently the indeices has been modified
var ops = d.splice(5,10);
var ops = ops.filter(function(x){return x !== ""});
//Loop through options and add to question
var ch = options.map(function(option, op){
var tf = ops[op];
return mcItem.createChoice(option, tf);
});

mcItem.setChoices(ch);
var correctFeedback = FormApp.createFeedback()
.setText(d[3])
.build();
mcItem.setFeedbackForCorrect(correctFeedback);
}

Trying to add up points for correct answers in a quiz in Python

The main problem is that you're resetting points to 0 inside the loop, which means that can only ever be either 0 or 1. The business with index is confusing and might be making it difficult to debug the points stuff; I suggest just using zip instead to make the whole thing easier:

points = 0
for correct, candidate in zip(correct_answers, candidate_answers):
if correct.lower() == candidate.lower():
points += 1
print(f'Your Answer: {candidate}\nCorrect Answer: {correct}')
else:
print('Incorrect.\nThe correct answer is: ', correct)
print(points)

Add answers from a loop into a list

Create a empty list and append the result to it

import itertools
n = 100
res = []
r = np.random.RandomState()
p = np.zeros(n)
for _ in itertools.repeat(p, 10):
n = 100
for k in range(99):
p[0] = 0.0
for i in range(n-1):
if (r.rand() >= 0.5):
p[i+1] = p[i] + 1.
else:
p[i+1] = p[i] - 1.
res.append(p[99])
print(res)

Output:

[-11.0, 3.0, 3.0, 3.0, -15.0, -5.0, 11.0, 5.0, -1.0, -9.0]

How to add and edit a short answer in multiple google forms

I managed to solve this issue that I was having, through looking for different codes and here are the codes that I used.

N.B. The codes might not be very clean as I was copying them from other parts/projects, but they have worked for me

1- Update the 20 forms with adding the access code question, I figured it was not possible to add a question at a certain position in the google form, however I can add a question at the end of the form and then move this item to the position I want:

    function AddAccesscodeQ() {
var filess = DriveApp.getFolderById("Drive id>").getFiles();
while (filess.hasNext()) {
var file = filess.next();
var form = FormApp.openById(file.getId());

var sectionIndex= 0; // Please set the index you want to insert.

//I added a "sample item" to be moved and edited later
var newItemQ = form.addTextItem().setTitle("New sample item").getIndex(); // New sample item
// I added a Pagebreak that also should be moved after the questions "Enter Your Access Code"
var newItemPB = form.addPageBreakItem().getIndex();

var items = form.getItems(FormApp.ItemType.PAGE_BREAK);
var sections = [0];
for (var i = 0; i < items.length; i++) {
// I pushed the items in the google form twice downwards, to be able to move the "sample item" and "Page break" to the top of the form
sections.push(items[i].getIndex());
sections.push(items[i].getIndex());

}
var insertIndex = sections[sectionIndex + 1] || null;
if (insertIndex) {
// Here I moved the 2 new items to the desired positions
form.moveItem(newItemQ, 0);
form.moveItem(newItemPB, 1);
}
// Here I am going to edit the "Sample Question" to be as desired
var itemss = form.getItems();
var itemID = itemss[0].getId();
var itemse = form.getItemById(itemID).asTextItem()
.setTitle('Enter Your Access Code').setRequired(true);
//Create validation rule
var validation = FormApp.createTextValidation()
.setHelpText('Invalid Code')
.requireTextMatchesPattern("<Access Code>")
.build();
itemse.setValidation(validation);
}
}

2- The second problem was that I later might need to change this access code to a new one for the 20 forms

function UpdateAccessCode() {
var filesPhCH = DriveApp.getFolderById("<Drive ID>").getFiles();
while (filesPhCH.hasNext()) {
var file = filesPhCH.next();
var form = FormApp.openById(file.getId());
var items = form.getItems();

//Loop through the items and list them
for (var i = 0;i<items.length;i++){
var item = items[i];
var itemID = item.getId();
var itemtitle = item.getTitle();
var itemindex = item.getIndex();
// I found no need to continue the for loop since the items that need modification are at the top of the form
if (itemindex == 0){
break;
}
}
//Select the question you want to update
var itemse = form.getItemById(itemID).asTextItem()
.setTitle('Enter Your Access Code');
//Create validation rule
var validation = FormApp.createTextValidation()
//.setTitle('Enter Your Access Code');
.setHelpText('Invalid Code')
.requireTextMatchesPattern("<Enter the new Access Code>")
.build();

itemse.setValidation(validation);
}
}

I hope this might help someone as it has saved a lot of time for me ;)

How to insert an answer into python [closed]

If you want to get it so that Python asks the user "What is the most popular search engine?" and then stores the answer in a variable then you should use the input() method.

popularSearchEngine = input("What is the most popular search engine? ")

What this does it it prints "What is the most popular search engine?" and then waits for the user to enter something. Whatever the user enters is then stored in the variable popularSearchEngine.

Now, if you wanted to check to see if the user entered 'google', you could just use a basic if statement. I would recommend using strip() and lower() so that what the user enters does not have to be case-sensitive.

popularSearchEngine = input("What is the most popular search engine? ")

if popularSearchEngine.strip().lower() == 'google':
# Run this code if user enters 'GOOGLE' or 'GooGLE' or ' gOoGlE'


Related Topics



Leave a reply



Submit