Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 123 discussion

Actual exam question from Python Institute's PCAP
Question #: 123
Topic #: 1
[All PCAP Questions]

A Python module named pymod.py contains a variable named pyvar.
Which of the following snippets will let you access the variable? (Choose two.)

  • A. import pymod pymod.pyvar = 1
  • B. import pyvar from pymod pyvar = 1
  • C. from pymod import pyvar pyvar ()
  • D. from pyfun import * pyvar = 1
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
macxsz
Highly Voted 2 years, 6 months ago
Only correct is: A. import pymod pymod.pyvar = 1
upvoted 6 times
...
46a1b89
Most Recent 1 month ago
C and D
upvoted 1 times
...
zantrz
9 months, 2 weeks ago
Selected Answer: D
In my opinion there is a typo mistake. In answer D there should be: D. from pymod import * pyvar = 1 The correct two answers would be be A and D. I think that C cannot work due to =(). C. from pymod import pyvar; pyvar() This imports the variable pyvar directly from the module pymod and assigns it to the local namespace. Then, it tries to call pyvar as a function, which may raise a TypeError depending on the content of pyvar.
upvoted 2 times
...
Damon54
9 months, 2 weeks ago
A e C correct
upvoted 1 times
...
temor
10 months ago
Selected Answer: A
A. import pymod followed by pymod.pyvar = 1: This approach imports the module pymod and then accesses the variable pyvar as an attribute of the module. C. from pymod import pyvar: This approach directly imports the pyvar variable from the pymod module, making it accessible without referencing the module name. The other options are incorrect: B. import pyvar from pymod is not valid syntax for importing a variable. You should use from pymod import pyvar to import the variable correctly. D. from pyfun import * pyvar = 1 is attempting to import all functions and variables from a module named pyfun, which is not mentioned in the question. It's unrelated to the pymod module and pyvar variable. So, options A and C are the correct ways to access the pyvar variable from the pymod.py module.
upvoted 1 times
...
DezzoPalYeah
1 year, 1 month ago
Answer is A,C
upvoted 1 times
...
Nenggg
1 year, 11 months ago
Selected Answer: A
A is correct
upvoted 1 times
...
rotimislaw
2 years ago
Selected Answer: A
A. import pymod pymod.pyvar = 1 Correct B. import pyvar from pymod pyvar = 1 Incorrect C. from pymod import pyvar pyvar() Incorrect D. from pyfun import * pyvar = 1 Incorrect There's another option to A. presented above, but neither B nor C meets it in full: from pymod import pyvar #see the order of 'from' and 'import' pyvar = 1 #no '()' after pyvar variable name
upvoted 1 times
...
Dav023
2 years, 1 month ago
All options ar incorrect. Use this snippets to test them from math import pi print(pi)
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...