Afternoon brain Watt, thought for a while did not come up with algorithms, just convulsions finally realized, hereby recorded.  ̄- ̄| |Topic(a) Create a function with the name FINDCHR (), FINDCHR () to find the character char in string strings, find the index that returns the value, otherwise return-1.(b) Create another function called RFINDCHR (), looking for the character char last occurrence. It works like FINDCHR (), but it looks forward from the end of the string.(c) Create a third function,
Python core Programming (third edition), after-school problem solving, chapter two. All the answers are for bloggers to write their own, because the level is limited, welcome to put forward opinions, mutual exchanges.
2-1. What is the difference between a connection-oriented socket and a connectionless socket.
Connection-oriented: Before communication, a connect
), Global Namespaces (Globals Namespaces), and built-in namespaces (Build-in namespaces).Build-in namespaces is first loaded into the active namespaces by the Python interpreter, which is made up of the names in the __buildins__ module.Global namespaces is then loaded as an active namespaces, and you can use the Globals () built-in function to determine whether a name belongs to the global namespace.Local namespaces when needed, that is, if a function
2-5 Loops and Numbersa) i = 0While I Print Ii + = 1b) for I in Range (0,11):Print I2-6 conditionalsN =int (raw_input (' Enter a number: '))If n print ' negative 'Elif n > 0:print ' positive 'Elseprint ' zero '2-7 Loops and stringss = Raw_input (' Enter a string: ')For Each_char in S:Print Each_charOrFor I in range (len (s)):Print I,s[i]Ori = 0Slen = Len (s)While I Print I,s[i]I +=1OrFor I,x in enumerate (s):Print I,x2-8 Loops and operatorsSubtot = 0For I in range (5):Subtot + = Int (raw_input ('
: Finally10-5. Exceptions. What exceptions will be thrown by the Python code snippet below these interaction interpreters (see the list of built-in exceptions given in Table 10.2):(a) >>>if 3 (b) >>>alist = [' Hello ', ' world ', ' anyone ', ' Home ']>>>print ' The last string of alist is: ', Alist[len (alist)](c) >>>x(d) >>>x = 4 0(e) >>>import Math>>>i = math.sqrt (-1)(a) Syntaxerror:invalid syntax (b) indexerror:list index out of range (c) nameerro
numeric operation built-in function
functions
nbsp; function
ABS (num)
Returns the absolute value of num
Coerce (NUM1, num2) The
Converts NUM1 and num2 to the same type and then returns as a tuple.
Divmod (NUM1, num2)
Division-the combination of the take redundancy operation. Returns a tuple (Num1/num2,num1%num2). The quotient of floating-point
1 #coding:utf-8 # using Windows system, first line ' #!/usr/bin/env Pyton ' useless, all changed to ' # Coding:utf-8 '2 3 'readtextfile.py--Read and display text file'4 5 #get filename6fname = Raw_input ('Enter FileName:')7 Print8 9 #attempt to open file for readingTen Try: OneFobj = open (fname,'R') # Try to open fname A exceptIOError, E:#The detailed cause of the captured IOError error is placed in Object E, and then the except code block that runs the exception (can also be written
Note: I use the python3.5. where range and Xrange,input and Raw_input have been merged8-1. Conditional statements. Take a look at the following code:# statement AIf x > 0:# statement BPassElif x # statement CPassElse# statement DPass# statement E(a) If x(b) If x=0, which of the above statements will be executed?(c) If x>0, which of the above statements will be executed?(a) ACE, (b) ADE, (c) ABE8-2. cycle. Write a program that allows the user to enter 3 numbers: (f) ROM, (t) O and (i) ncrement. T
Java programming ideology fourth edition Chapter 3 personal exercises, programming ideology Fourth Edition
I hope you will be grateful for your criticism ......)Chapter 3 exercise 9 (1) show the maximum and minimum numbers represented by float and double indexes respectively
public class MaxMinFloatDouble {
C ++ programming ideology (second edition) Chapter 2nd object creation and use (exercises and answers), java programming ideology (second edition)
Exercise-related code
Hello. cpp
Stream2.cpp
Nomconv.cpp
Fillvector.cpp
2-1 modify Hello. cpp so that he can print your name and age (or your shoes, dog's age, etc., as l
Author: Brian W. Kernighan/(Mei) Dennis M. RitchiePublishing house: Mechanical Industry PressSubtitle: 2nd edition • NewOriginal name: The C programming LanguageTranslator: Baowen Xu/li zhi/Yu Jinyuan revisionPublication year: 2004-1Number of pages: 258Price: 30.00 RMBBinding: Paperbackisbn:9787111128069Content profile ...In the history of computer development, no progr
represent more than just numeric values, but also other data types, such as objects.FunctionGrammarfunction funcname (formal parameter) {function body}funcname (actual argument)Formal parameters are also local variablesfunction FuncName (parameter var funcname; local Variables}FuncName (argument value) argument is a global variableIn JS, function in parentheses inside the parameters, no matter how much or do not give, JS will never error, will not care about the parameters passed in isWhat type
get a runtime error called an EX Ception.Downcasting and the runtime checks require extra time for the running program and extra effort from the programmer.The solution is called a parameterized type mechanism. (Java se5,called generics)A parameterized type (compiler-level technology) is a class, the compiler can automatically customize to work with particular Types.Object Creation LifetimeWhen to destroy object?C + + takes the approach that control of efficiency are the most important issue,
objects of a known type,can is multidimensional, can hold primitived. However, its size cannot is changed once you create it.2. Collection:hold single elements, automatically resize, won ' t hold Primitives3. Map:holds associated pairs, automatically resize, won ' t hold Primitives4. Like an array, a List of also associated numerical indexes to Objects--thus,arrays and Lists is ordered containers.5. The behavior of Queues and stacks is provided via the LinkedList6. A Map is a-to-associate not i
to call inside a constructor is those that is final in the base class. (This also applies to private methods, which is automatically final.)Convariant return typesJava SE5 adds convariant return types, which means, a overridden method in a derived class can return a type derived From the type returned by the Base-class methodDesigning with InheritanceIf you choose inheritance First when you ' re using a existing class to make a new class, things can become needlessly comp Licated.A better appro
Problem DescriptionThis day the teacher gave small Hao a very simple topic relaxed: Enter a score, let you find their simplest score. InputThe first line includes a T, which represents the number of groups of test data.The next line of T lines includes a fraction. (The numerator denominator is within the int range)OutputFor each test sample, the output line has its simplest fraction.Sample Input32/63/111/36Sample Output1/33/111/36My Code:1#include 2ProcessintAintb/*greatest common divisor, so th
Problem DescriptionThe teacher gave a title to Xiao Hao: give you two integers x and n ( -10now that little Howe is in a quandary, please help him solve the problem. InputEnter two integers x and n per line.Outputfor each set of test data, the output line evaluates. Sample Input1 12 2Sample Output16HINT1#include 2 3 4 Long LongSumintXintN)5 {6 Long Longs=0;7 inti,j;8 Long LongS1;9 for(i=1; i)Ten { Ones1=1; A for(j=1; j) - { -s1*=x; the } -s+=S1; - } -
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.