Jump to content

Truman

Members
  • Content count

    105
  • Joined

  • Last visited

Everything posted by Truman

  1. Problem with random

    If anyone wants to know I had to install python again with pip, now it works fine.
  2. Problem with random

    I intend to make lottery drawing program but first wanted to check the basic random module with a code: from random import * print(randint(1, 100)) Instead I receive a comment from cmd that contains output of some other file that I created None of my files is named random.py. I have no idea how is this possible.
  3. Break statement code

    for n in range(2, 10): for x in range(2, n): if n % x == 0: print(n, 'equals', x, '*', n//x) break else: print(n, 'is a prime number') There are two issues here: 1. TabError: Incosistent use of tabs and spaces in indentation 2. More importantly I don't understand the logic behind this code that leads to this output:
  4. Break statement code

    Interesting note, will keep that in my mind. Error message points to line 5 - break.
  5. Break statement code

    Actually, else is lined up with for in official python tutorial and when I change it to what you suggested nothing changes...
  6. For statement with slice copy

    Hi, I'm looking at this piece of code: words = ['cat', 'window', 'defenestrate'] for w in words[:]: if len(w) > 6: words.insert(0, w) words ['defenestrate', 'cat', 'window', 'defenestrate'] If I understand well it should make copy of the list and add 'defenestrate' into list but I receive a message "tuple object has no attribute instert". This code is a part of a tutorial I'm following and not sure why it doesn't work.
  7. Break statement code

    This is how my code actually looks like in notepad++. From some reason forum <> function doesn't paste code with the same indentation. Regarding the understanding of the code I understand mod operator but my miscomprehension was due to relation between for and else. Mixed things, now it's clearer.
  8. For statement with slice copy

    words = ['book', 'superficial', 'nostradamus'] for w in words: print(w, len(w)) for w in words[:]: if len(w) > 6: words.insert(0, w) words ['defenestrate', 'cat', 'window', 'defenestrate'] this is my code.
  9. For statement with slice copy

    You're correct but after changing it to square brackets I receive TypeError: list indices must be integer or slices, not tuple.
  10. For statement with slice copy

    It looks so, you can find it here: https://docs.python.org/3.6/tutorial/controlflow.html 4.2. for Statements
  11. Why this code doesn't run?

    I'm working on my php skills and I run .php files on XAMPP server but it signals parse error even when php code checker sees no problem. This is one of the codes that I wrote: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>5 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Quotes</title> </head> <body> <?php // Script 2.4 - pursue3.php $name = "M"; $age = 29; $lastname = 'B'; $nationality = "S"; print "<h1>Basic Info</h1><p>My name is $name, I am $age years old.<br/>My nationality is $nationality. My lastname is $lastname</p>" ?> </body> </html> When I execute this code on my localhost it says: "Parse error: syntax error, unexpected '?' in C:\xampp\htdocs\my-site\pursue3.php on line 18" It happened with last 3 php files that I wrote. I know what a parse error is, I just don't see where I made any mistake.
  12. Why this code doesn't run?

    Thanks, I closed php code before <!DOCTYPE...>' and now it works...
  13. Why this code doesn't run?

    How could I know that the error is on line 3 of another file? And this is the code for header.html: <?php // Script 1.4 - header.html include('functions.php'); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" media="all" href="css/style.css" /> <title><?php if (defined('TITLE')) { print TITLE; } else { print 'My site of quotes.'; } ?></title> </head> <body> <div id="container"> <h1>My site of quotes.</h1> <br /> <! -- Begin changeable content. -->
  14. Why this code doesn't run?

    I wrote a simple code for logout: <?php // Script 1.7 - logout.php if (isset($_COOKIE['Samuel'])) { setcookie('Samuel', FALSE, time()-300); } define('TITLE', 'Logout'); include('templates/header.html'); print '<p>You are now logged out.</p>'; include('templates/footer.html'); ?> but I receive: Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\my-site\all\templates\header.html on line 3 This makes no sense to me...
  15. Handling file uploads

    I wrote this correct code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Upload a File</title> </head> <body> <?php // Script 11.4 - upload_file.php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (move_uploaded_file($FILES['the_file']['tmp_name'],"../uploads/{$_FILES['the_file']['name']}")) { print '<p>Your file has been uploaded.</p>'; } else { print '<p style="color:red;">Your file could not be uploaded because: '; switch($_FILES['the_file']['error']) { case 1: print 'The file exeeds upload_max_filesize setting in php.ini'; break; case 2: print 'The file exeeds MAX_FILE_SIZE setting in the HTML form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded.'; break; case 6: print 'The temporary folder does not exist.'; default: print 'Somethin unforseen happened.'; break; print '.</p>'; } } } ?> <form action="upload_file.php" enctype="multipart/form-data" method="post"> <p>Upload a file using this form: </p> <input type="hidden" name="MAX_FILE_SIZE" value="300000" /> <p><input type="file" name="the_file" /></p> <p><input type="submit" name="submit" value="Upload this file" /></p> </form> </body> </html> I ran this code through browser, uploaded a file that I named 'the_file' and I received error 6: Your file could not be uploaded because: Something unforseen happened. Is there something that I'm missing here?
  16. Handling file uploads

    Actually this '$FILES' was a mistake, when I corrected it worked! I already made uploads directory for this purpose. I will also take a look on other suggestions that you and your colleagues gave me on this topic.
  17. Handling file uploads

    After adding error 7 and error 8 I still receive the default error message.
  18. Handling file uploads

    After making those changes I still receive the same note. I use XAMPP server, can you please shortly explain me how to set it up?
  19. Why this code doesn't run?

    Oh, I see. Thank you. Do you think that Sublime Text is good for that purpose? Someone recommended it to me...
  20. Why this code doesn't run?

    Thank you, now other mistake is reported, but I won't bother you with that. Do you think that online php code checker is good? It usually sends the same message as browser.
  21. Why this code doesn't run?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Date Menus</title> </head> <body> <?php // Script 10.1 - menus.php function make_date_menus() { $months = array(1 => 'January', 'February', 'March', 'Aprile', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); print '<select name="month">'; foreach ( $month as $key => $value ) { print "\n<option value=\"$key\">$value</option>"; } print '</select>'; print '<select name="day">'; for ($day=0; $day<=31; $day++) { print "\n<option value=\"$day\">$day</option>"; } print '</select>'; print '<select name="year"> $start_year = date('Y'); for ($y = $start_year; $y <= ($start_year + 10); $y++ ) { print "\n<option value=\"year\">$y</option>"; } print '</select>'; } // end of make_date_menus function. print '<form action="" method="post">'; make_date_menus(); print '</form>'; ?> </body> </html> and the error is: Parse error: syntax error, unexpected 'Y' (T_STRING) in C:\xampp\htdocs\my-site\menus.php on line 23 I don't see why 'Y' is an error, I used already existing function...
  22. Why this code doesn't run?

    I give up, totally lost with this synrax...
  23. Why this code doesn't run?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>View Your Settings</title> <style type="text/css"> body { font-size: x-large; color: #999; } <?php // Script 9.2 - view_settings.php if (isset($_COOKIES['font_size'])) { print "\t\tfont-size: " . htmlentites($_COOKIES['font_size']) . "; \n } else { print "font-size: medium;"; } if (isset($_COOKIES['font_color'])) { print "color: #" . htmlentities($_COOKIES['font_color']) . ";\n"; } else { print "\t\tcolor: #ooo;"; } ?> </style> </head> <body> <p><a href="customize.php">Customize your settings.</a></p> <p><a href="reset.php">Reset your settings.</a></p> <p>yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda yadda</p> </body> </html> Can you please tell me why I receive this message> Parse error: syntax error, unexpected 'size' (T_STRING) in C:\xampp\htdocs\my-site\view_settings.php on line 15 line 15 is: print "font-size: medium;";
  24. Why this code doesn't run?

    Can you please take a look at this code, from some reason it doesn't work. <?php // Script 8.9 - register.php define ('DEFINE', 'register'); include('templates/header.html'); print '<h2>Registration Form</h2> <p>Register so that you can take advantage of certain features like this, that, and the other things</p>'; print '<style type="text/css" media="screen"> .error { color: red; } </style>'; if ($_SERVER['REQUESTED_METHOD'] == 'POST') { $problem = FALSE; if (empty($_POST['first_name'])) { $problem = TRUE; print '<p class="error">Please enter your first name!</p>'; } if (empty($_POST['last_name'])) { $problem = TRUE; print '<p class="error">Please enter your last name!</p>'; } if (empty($_POST['email'])) { $problem = TRUE; print '<p class="error">Please enter your email address.</p>'; } if (empty($_POST['password1'])) { $problem = TRUE; print '<p class="error">Please enter a password.</p>'; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print '<p class="error">Your password did not match your confirm password.</p>'; } if (!$problem) { print '<p>You are now registered.</p>'; } $_POST = array(); } else { print '<p class="error">Please try again!</p>'; } ?> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])) { print htmlspecialchars($_POST['first_name']); } ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])) { print htmlspecialchars($_POST['last_name']); } ?>" /></p> <p>Email: <input type="text" name="email" size="20" value="<?php if (isset($_POST['email']) { print htmlspecialchars($_POST['email']);} ?> /></p> <p>Password: <input type="password" name="password1" size="20" value="<?php if (isset($_POST['password1']) { print htmlspecialchars($_POST['password']); } ?> /></p> <p>Confirm Password: <input type="password" name="password2" size="20" value="<?php if (isset($_POST['password2'])) { print htmlspecialchars ($_POST[password2']); } ?>" /></p> <p><input type="submit" name="submit" value="Register!"> /></p> </form> <?php include('templates/footer.html'); ?> I receive a note: Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\my-site\register.php on line 46 line 46 is: <p>Email: <input type="text" name="email" size="20" value="<?php if (isset($_POST['email']) { print
  25. Not understanding if-else statement

    I'm working of registration form and I have a problem with understanding one of the codes. <?php // Script 8.9 - register.php define ('DEFINE', 'register'); include('templates/header.html'); print '<h2>Registration Form</h2> <p>Register so that you can take advantage of certain features like this, that, and the other things</p>'; print '<style type="text/css" media="screen"> .error { color: red; } </style>'; if ($_SERVER['REQUESTED_METHOD'] == 'POST') { $problem = FALSE; if (empty($_POST['first_name'])) { $problem = TRUE; print '<p class="error">Please enter your first name!</p>'; } if (empty($_POST['last_name'])) { $problem = TRUE; print '<p class="error">Please enter your last name!</p>'; } if (empty($_POST[email'])) { $problem = TRUE; print '<p class="error">Please enter your email address.</p>'; } if (empty($_POST['password1'])) { $problem = TRUE; print '<p class="error">Please enter a password.</p>'; } if ($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print '<p class="error">Your password did not match your confirm password.</p>'; } if (!$problem) { print '<p>You are now registered.</p>' } $_POST = array(); } else { print '<p class="error">Please try again!</p> } } ?> this part: if (!$problem) { print '<p>You are now registered.</p>' } Why are we using exclamation mark here? I already defined $problem = FALSE at the beginning of the whole code. That means that there is no problem. If we reverse it to TRUE it will mean that there is a problem with registration but in that case the user shouldn't see "You are now registered". The if condition is fulfilled in any case because with don't have any '<', '>' or '=='.
×